{"action":"created","comment":{"url":"https://api.github.com/repos/SAP/jenkins-library/pulls/comments/166017798","pull_request_review_id":94019640,"id":166017798,"diff_hunk":"@@ -0,0 +1,138 @@\n+import com.sap.piper.ConfigurationLoader\n+import com.sap.piper.ConfigurationMerger\n+import com.sap.piper.GitUtils\n+import com.sap.piper.Utils\n+import com.sap.piper.versioning.ArtifactVersioning\n+\n+import groovy.text.SimpleTemplateEngine\n+\n+def call(Map parameters = [:]) {\n+\n+    def stepName = 'artifactSetVersion'\n+\n+    handlePipelineStepErrors (stepName: stepName, stepParameters: parameters) {\n+\n+        def gitUtils = parameters.juStabGitUtils\n+        if (gitUtils == null) {\n+            gitUtils = new GitUtils()\n+        }\n+\n+        //ToDo: exit if pending git changes are in the current repo? TBD!\n+\n+        def script = parameters.script\n+        if (script == null)\n+            script = [commonPipelineEnvironment: commonPipelineEnvironment]\n+\n+        prepareDefaultValues script: script\n+\n+        final Map stepDefaults = ConfigurationLoader.defaultStepConfiguration(script, stepName)\n+        final Map stepConfiguration = ConfigurationLoader.stepConfiguration(script, stepName)\n+\n+        List parameterKeys = [\n+            'artifactType',\n+            'buildTool',\n+            'dockerVersionSource',\n+            'filePath',\n+            'gitCommitId',\n+            'gitCredentialsId',\n+            'gitUserEMail',\n+            'gitUserName',\n+            'gitSshUrl',\n+            'tagPrefix',\n+            'timestamp',\n+            'timestampTemplate',\n+            'versioningTemplate'\n+        ]\n+        Map pipelineDataMap = [\n+            gitCommitId: gitUtils.getGitCommitId()\n+        ]\n+        List stepConfigurationKeys = [\n+            'artifactType',\n+            'buildTool',\n+            'dockerVersionSource',\n+            'filePath',\n+            'gitCredentialsId',\n+            'gitUserEMail',\n+            'gitUserName',\n+            'gitSshUrl',\n+            'tagPrefix',\n+            'timestamp',\n+            'timestampTemplate',\n+            'versioningTemplate'\n+        ]\n+\n+        Map configuration = ConfigurationMerger.mergeWithPipelineData(parameters, parameterKeys, pipelineDataMap, stepConfiguration, stepConfigurationKeys, stepDefaults)\n+\n+        //buildTool is mandatory parameter\n+        def utils = new Utils()\n+        def buildTool = utils.getMandatoryParameter(configuration, 'buildTool')\n+\n+        if (!configuration.filePath)\n+            configuration.filePath = configuration[buildTool].filePath //use default configuration\n+\n+        def newVersion\n+        def artifactVersioning = ArtifactVersioning.getArtifactVersioning(buildTool, this, configuration)\n+\n+        if(configuration.artifactType == 'appContainer' && configuration.dockerVersionSource == 'appVersion'){\n+            if (script.commonPipelineEnvironment.getArtifactVersion())\n+                //replace + sign if available since + is not allowed in a Docker tag\n+                newVersion = script.commonPipelineEnvironment.getArtifactVersion().replace('+', '_')\n+            else\n+                error (\"[${stepName}] No artifact version available for 'dockerVersionSource: appVersion' -> executeBuild needs to run for the application artifact first to set the artifactVersion for the application artifact.'\")\n+        } else {\n+            def currentVersion = artifactVersioning.getVersion()\n+\n+            def timestamp = configuration.timestamp ? configuration.timestamp : getTimestamp(configuration.timestampTemplate)\n+\n+            def versioningTemplate = configuration.versioningTemplate ? configuration.versioningTemplate : configuration[configuration.buildTool].versioningTemplate\n+            //defined in default configuration\n+            def binding = [version: currentVersion, timestamp: timestamp, commitId: configuration.gitCommitId]\n+            def templatingEngine = new SimpleTemplateEngine()\n+            def template = templatingEngine.createTemplate(versioningTemplate).make(binding)\n+            newVersion = template.toString()\n+        }\n+\n+        artifactVersioning.setVersion(newVersion)\n+\n+        sh 'git add .'\n+\n+        def gitCommitId\n+\n+        sshagent([configuration.gitCredentialsId]) {\n+            if (configuration.gitUserName  && configuration.gitUserEMail) {\n+                sh \"git config user.name \\\"${configuration.gitUserName}\\\"\"","path":"vars/artifactSetVersion.groovy","position":103,"original_position":103,"commit_id":"d787d89abce863bfc512abfc3d4b27e19ac5721d","original_commit_id":"d787d89abce863bfc512abfc3d4b27e19ac5721d","user":{"login":"marcusholl","id":1853183,"avatar_url":"https://avatars2.githubusercontent.com/u/1853183?v=4","gravatar_id":"","url":"https://api.github.com/users/marcusholl","html_url":"https://github.com/marcusholl","followers_url":"https://api.github.com/users/marcusholl/followers","following_url":"https://api.github.com/users/marcusholl/following{/other_user}","gists_url":"https://api.github.com/users/marcusholl/gists{/gist_id}","starred_url":"https://api.github.com/users/marcusholl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcusholl/subscriptions","organizations_url":"https://api.github.com/users/marcusholl/orgs","repos_url":"https://api.github.com/users/marcusholl/repos","events_url":"https://api.github.com/users/marcusholl/events{/privacy}","received_events_url":"https://api.github.com/users/marcusholl/received_events","type":"User","site_admin":false},"body":"Why updating the config in the local git repo here? This lines can be ommited when we use later\r\n```git -c user.email=\"${configuration.gitUserEmail}\" -c user.name \"${configuration.gitUserName}\" commit -m \"'update version ${newVersion}'\"``` \r\nWith that it is also more transparent which commands makes use of which settings. E.g. for the push these settings are not needed.","created_at":"2018-02-05T16:01:43Z","updated_at":"2018-02-05T16:25:51Z","html_url":"https://github.com/SAP/jenkins-library/pull/65#discussion_r166017798","pull_request_url":"https://api.github.com/repos/SAP/jenkins-library/pulls/65","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/SAP/jenkins-library/pulls/comments/166017798"},"html":{"href":"https://github.com/SAP/jenkins-library/pull/65#discussion_r166017798"},"pull_request":{"href":"https://api.github.com/repos/SAP/jenkins-library/pulls/65"}}},"pull_request":{"url":"https://api.github.com/repos/SAP/jenkins-library/pulls/65","id":166585424,"html_url":"https://github.com/SAP/jenkins-library/pull/65","diff_url":"https://github.com/SAP/jenkins-library/pull/65.diff","patch_url":"https://github.com/SAP/jenkins-library/pull/65.patch","issue_url":"https://api.github.com/repos/SAP/jenkins-library/issues/65","number":65,"state":"open","locked":false,"title":"Step for automatic versioning","user":{"login":"OliverNocon","id":33484802,"avatar_url":"https://avatars2.githubusercontent.com/u/33484802?v=4","gravatar_id":"","url":"https://api.github.com/users/OliverNocon","html_url":"https://github.com/OliverNocon","followers_url":"https://api.github.com/users/OliverNocon/followers","following_url":"https://api.github.com/users/OliverNocon/following{/other_user}","gists_url":"https://api.github.com/users/OliverNocon/gists{/gist_id}","starred_url":"https://api.github.com/users/OliverNocon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OliverNocon/subscriptions","organizations_url":"https://api.github.com/users/OliverNocon/orgs","repos_url":"https://api.github.com/users/OliverNocon/repos","events_url":"https://api.github.com/users/OliverNocon/events{/privacy}","received_events_url":"https://api.github.com/users/OliverNocon/received_events","type":"User","site_admin":false},"body":"It contains:\r\n* versioning step artifactSetVersion\r\n* versioning implementation for Maven & Docker\r\n* enhancements to commonPipelineEnvironment\r\n* new default configuration\r\n* new utils object for git-related tasks\r\n* automated tests incl. new Rules and resources\r\n\r\nSo far missing:\r\n* versioning implementations for additional technologies\r\n* documentation","created_at":"2018-02-01T16:25:46Z","updated_at":"2018-02-05T16:25:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cb71deff432cccf1e3758719f2fb9a75761f0010","assignee":null,"assignees":[],"requested_reviewers":[{"login":"nevskrem","id":33895725,"avatar_url":"https://avatars3.githubusercontent.com/u/33895725?v=4","gravatar_id":"","url":"https://api.github.com/users/nevskrem","html_url":"https://github.com/nevskrem","followers_url":"https://api.github.com/users/nevskrem/followers","following_url":"https://api.github.com/users/nevskrem/following{/other_user}","gists_url":"https://api.github.com/users/nevskrem/gists{/gist_id}","starred_url":"https://api.github.com/users/nevskrem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nevskrem/subscriptions","organizations_url":"https://api.github.com/users/nevskrem/orgs","repos_url":"https://api.github.com/users/nevskrem/repos","events_url":"https://api.github.com/users/nevskrem/events{/privacy}","received_events_url":"https://api.github.com/users/nevskrem/received_events","type":"User","site_admin":false}],"requested_teams":[],"milestone":null,"commits_url":"https://api.github.com/repos/SAP/jenkins-library/pulls/65/commits","review_comments_url":"https://api.github.com/repos/SAP/jenkins-library/pulls/65/comments","review_comment_url":"https://api.github.com/repos/SAP/jenkins-library/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SAP/jenkins-library/issues/65/comments","statuses_url":"https://api.github.com/repos/SAP/jenkins-library/statuses/d787d89abce863bfc512abfc3d4b27e19ac5721d","head":{"label":"SAP:versioning","ref":"versioning","sha":"d787d89abce863bfc512abfc3d4b27e19ac5721d","user":{"login":"SAP","id":2531208,"avatar_url":"https://avatars1.githubusercontent.com/u/2531208?v=4","gravatar_id":"","url":"https://api.github.com/users/SAP","html_url":"https://github.com/SAP","followers_url":"https://api.github.com/users/SAP/followers","following_url":"https://api.github.com/users/SAP/following{/other_user}","gists_url":"https://api.github.com/users/SAP/gists{/gist_id}","starred_url":"https://api.github.com/users/SAP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SAP/subscriptions","organizations_url":"https://api.github.com/users/SAP/orgs","repos_url":"https://api.github.com/users/SAP/repos","events_url":"https://api.github.com/users/SAP/events{/privacy}","received_events_url":"https://api.github.com/users/SAP/received_events","type":"Organization","site_admin":false},"repo":{"id":107318996,"name":"jenkins-library","full_name":"SAP/jenkins-library","owner":{"login":"SAP","id":2531208,"avatar_url":"https://avatars1.githubusercontent.com/u/2531208?v=4","gravatar_id":"","url":"https://api.github.com/users/SAP","html_url":"https://github.com/SAP","followers_url":"https://api.github.com/users/SAP/followers","following_url":"https://api.github.com/users/SAP/following{/other_user}","gists_url":"https://api.github.com/users/SAP/gists{/gist_id}","starred_url":"https://api.github.com/users/SAP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SAP/subscriptions","organizations_url":"https://api.github.com/users/SAP/orgs","repos_url":"https://api.github.com/users/SAP/repos","events_url":"https://api.github.com/users/SAP/events{/privacy}","received_events_url":"https://api.github.com/users/SAP/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SAP/jenkins-library","description":"Jenkins shared library for Continuous Delivery pipelines.","fork":false,"url":"https://api.github.com/repos/SAP/jenkins-library","forks_url":"https://api.github.com/repos/SAP/jenkins-library/forks","keys_url":"https://api.github.com/repos/SAP/jenkins-library/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SAP/jenkins-library/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SAP/jenkins-library/teams","hooks_url":"https://api.github.com/repos/SAP/jenkins-library/hooks","issue_events_url":"https://api.github.com/repos/SAP/jenkins-library/issues/events{/number}","events_url":"https://api.github.com/repos/SAP/jenkins-library/events","assignees_url":"https://api.github.com/repos/SAP/jenkins-library/assignees{/user}","branches_url":"https://api.github.com/repos/SAP/jenkins-library/branches{/branch}","tags_url":"https://api.github.com/repos/SAP/jenkins-library/tags","blobs_url":"https://api.github.com/repos/SAP/jenkins-library/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SAP/jenkins-library/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SAP/jenkins-library/git/refs{/sha}","trees_url":"https://api.github.com/repos/SAP/jenkins-library/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SAP/jenkins-library/statuses/{sha}","languages_url":"https://api.github.com/repos/SAP/jenkins-library/languages","stargazers_url":"https://api.github.com/repos/SAP/jenkins-library/stargazers","contributors_url":"https://api.github.com/repos/SAP/jenkins-library/contributors","subscribers_url":"https://api.github.com/repos/SAP/jenkins-library/subscribers","subscription_url":"https://api.github.com/repos/SAP/jenkins-library/subscription","commits_url":"https://api.github.com/repos/SAP/jenkins-library/commits{/sha}","git_commits_url":"https://api.github.com/repos/SAP/jenkins-library/git/commits{/sha}","comments_url":"https://api.github.com/repos/SAP/jenkins-library/comments{/number}","issue_comment_url":"https://api.github.com/repos/SAP/jenkins-library/issues/comments{/number}","contents_url":"https://api.github.com/repos/SAP/jenkins-library/contents/{+path}","compare_url":"https://api.github.com/repos/SAP/jenkins-library/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SAP/jenkins-library/merges","archive_url":"https://api.github.com/repos/SAP/jenkins-library/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SAP/jenkins-library/downloads","issues_url":"https://api.github.com/repos/SAP/jenkins-library/issues{/number}","pulls_url":"https://api.github.com/repos/SAP/jenkins-library/pulls{/number}","milestones_url":"https://api.github.com/repos/SAP/jenkins-library/milestones{/number}","notifications_url":"https://api.github.com/repos/SAP/jenkins-library/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SAP/jenkins-library/labels{/name}","releases_url":"https://api.github.com/repos/SAP/jenkins-library/releases{/id}","deployments_url":"https://api.github.com/repos/SAP/jenkins-library/deployments","created_at":"2017-10-17T20:14:48Z","updated_at":"2018-01-31T05:33:11Z","pushed_at":"2018-02-05T15:03:13Z","git_url":"git://github.com/SAP/jenkins-library.git","ssh_url":"git@github.com:SAP/jenkins-library.git","clone_url":"https://github.com/SAP/jenkins-library.git","svn_url":"https://github.com/SAP/jenkins-library","homepage":null,"size":813,"stargazers_count":30,"watchers_count":30,"language":"Groovy","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":16,"mirror_url":null,"archived":false,"open_issues_count":18,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":16,"open_issues":18,"watchers":30,"default_branch":"master"}},"base":{"label":"SAP:master","ref":"master","sha":"1eb035b5e1030afbb1cf33c9dd6df702e4055d30","user":{"login":"SAP","id":2531208,"avatar_url":"https://avatars1.githubusercontent.com/u/2531208?v=4","gravatar_id":"","url":"https://api.github.com/users/SAP","html_url":"https://github.com/SAP","followers_url":"https://api.github.com/users/SAP/followers","following_url":"https://api.github.com/users/SAP/following{/other_user}","gists_url":"https://api.github.com/users/SAP/gists{/gist_id}","starred_url":"https://api.github.com/users/SAP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SAP/subscriptions","organizations_url":"https://api.github.com/users/SAP/orgs","repos_url":"https://api.github.com/users/SAP/repos","events_url":"https://api.github.com/users/SAP/events{/privacy}","received_events_url":"https://api.github.com/users/SAP/received_events","type":"Organization","site_admin":false},"repo":{"id":107318996,"name":"jenkins-library","full_name":"SAP/jenkins-library","owner":{"login":"SAP","id":2531208,"avatar_url":"https://avatars1.githubusercontent.com/u/2531208?v=4","gravatar_id":"","url":"https://api.github.com/users/SAP","html_url":"https://github.com/SAP","followers_url":"https://api.github.com/users/SAP/followers","following_url":"https://api.github.com/users/SAP/following{/other_user}","gists_url":"https://api.github.com/users/SAP/gists{/gist_id}","starred_url":"https://api.github.com/users/SAP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SAP/subscriptions","organizations_url":"https://api.github.com/users/SAP/orgs","repos_url":"https://api.github.com/users/SAP/repos","events_url":"https://api.github.com/users/SAP/events{/privacy}","received_events_url":"https://api.github.com/users/SAP/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SAP/jenkins-library","description":"Jenkins shared library for Continuous Delivery pipelines.","fork":false,"url":"https://api.github.com/repos/SAP/jenkins-library","forks_url":"https://api.github.com/repos/SAP/jenkins-library/forks","keys_url":"https://api.github.com/repos/SAP/jenkins-library/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SAP/jenkins-library/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SAP/jenkins-library/teams","hooks_url":"https://api.github.com/repos/SAP/jenkins-library/hooks","issue_events_url":"https://api.github.com/repos/SAP/jenkins-library/issues/events{/number}","events_url":"https://api.github.com/repos/SAP/jenkins-library/events","assignees_url":"https://api.github.com/repos/SAP/jenkins-library/assignees{/user}","branches_url":"https://api.github.com/repos/SAP/jenkins-library/branches{/branch}","tags_url":"https://api.github.com/repos/SAP/jenkins-library/tags","blobs_url":"https://api.github.com/repos/SAP/jenkins-library/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SAP/jenkins-library/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SAP/jenkins-library/git/refs{/sha}","trees_url":"https://api.github.com/repos/SAP/jenkins-library/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SAP/jenkins-library/statuses/{sha}","languages_url":"https://api.github.com/repos/SAP/jenkins-library/languages","stargazers_url":"https://api.github.com/repos/SAP/jenkins-library/stargazers","contributors_url":"https://api.github.com/repos/SAP/jenkins-library/contributors","subscribers_url":"https://api.github.com/repos/SAP/jenkins-library/subscribers","subscription_url":"https://api.github.com/repos/SAP/jenkins-library/subscription","commits_url":"https://api.github.com/repos/SAP/jenkins-library/commits{/sha}","git_commits_url":"https://api.github.com/repos/SAP/jenkins-library/git/commits{/sha}","comments_url":"https://api.github.com/repos/SAP/jenkins-library/comments{/number}","issue_comment_url":"https://api.github.com/repos/SAP/jenkins-library/issues/comments{/number}","contents_url":"https://api.github.com/repos/SAP/jenkins-library/contents/{+path}","compare_url":"https://api.github.com/repos/SAP/jenkins-library/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SAP/jenkins-library/merges","archive_url":"https://api.github.com/repos/SAP/jenkins-library/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SAP/jenkins-library/downloads","issues_url":"https://api.github.com/repos/SAP/jenkins-library/issues{/number}","pulls_url":"https://api.github.com/repos/SAP/jenkins-library/pulls{/number}","milestones_url":"https://api.github.com/repos/SAP/jenkins-library/milestones{/number}","notifications_url":"https://api.github.com/repos/SAP/jenkins-library/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SAP/jenkins-library/labels{/name}","releases_url":"https://api.github.com/repos/SAP/jenkins-library/releases{/id}","deployments_url":"https://api.github.com/repos/SAP/jenkins-library/deployments","created_at":"2017-10-17T20:14:48Z","updated_at":"2018-01-31T05:33:11Z","pushed_at":"2018-02-05T15:03:13Z","git_url":"git://github.com/SAP/jenkins-library.git","ssh_url":"git@github.com:SAP/jenkins-library.git","clone_url":"https://github.com/SAP/jenkins-library.git","svn_url":"https://github.com/SAP/jenkins-library","homepage":null,"size":813,"stargazers_count":30,"watchers_count":30,"language":"Groovy","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":16,"mirror_url":null,"archived":false,"open_issues_count":18,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":16,"open_issues":18,"watchers":30,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SAP/jenkins-library/pulls/65"},"html":{"href":"https://github.com/SAP/jenkins-library/pull/65"},"issue":{"href":"https://api.github.com/repos/SAP/jenkins-library/issues/65"},"comments":{"href":"https://api.github.com/repos/SAP/jenkins-library/issues/65/comments"},"review_comments":{"href":"https://api.github.com/repos/SAP/jenkins-library/pulls/65/comments"},"review_comment":{"href":"https://api.github.com/repos/SAP/jenkins-library/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SAP/jenkins-library/pulls/65/commits"},"statuses":{"href":"https://api.github.com/repos/SAP/jenkins-library/statuses/d787d89abce863bfc512abfc3d4b27e19ac5721d"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"marcusholl"}}