diff --git a/tests/jenkins/TestStandardReleasePipelineWithGenericTriggers.groovy b/tests/jenkins/TestStandardReleasePipelineWithGenericTriggers.groovy index 8605ff79c..bab2c86d2 100644 --- a/tests/jenkins/TestStandardReleasePipelineWithGenericTriggers.groovy +++ b/tests/jenkins/TestStandardReleasePipelineWithGenericTriggers.groovy @@ -67,7 +67,7 @@ class TestStandardReleasePipelineWithGenericTriggers extends BuildPipelineTest { c -> c.contains('curl') } assertThat(cmd.size(), equalTo(1)) - assertThat(cmd, hasItem("curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer GIT_TOKEN' https://api.github.com/repos/Codertocat/Hello-World/releases/17372790 -d '{\"tag_name\":\"1.0.0\",\"draft\":false,\"prerelease\":false}'")) + assertThat(cmd, hasItem("curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer GITHUB_TOKEN' https://api.github.com/repos/Codertocat/Hello-World/releases/17372790 -d '{\"tag_name\":\"1.0.0\",\"draft\":false,\"prerelease\":false}'")) } diff --git a/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile.txt b/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile.txt index 4352967cf..e4e9b5776 100644 --- a/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile.txt +++ b/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile.txt @@ -11,6 +11,6 @@ standardReleasePipelineWithGenericTrigger.postCleanup() postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true}) standardReleasePipelineWithGenericTrigger.script(groovy.lang.Closure) - standardReleasePipelineWithGenericTrigger.string({credentialsId=jenkins-github-bot-token, variable=GIT_TOKEN}) - standardReleasePipelineWithGenericTrigger.withCredentials([GIT_TOKEN], groovy.lang.Closure) - standardReleasePipelineWithGenericTrigger.sh(curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer GIT_TOKEN' https://api.github.com/repos/Codertocat/Hello-World/releases/17372790 -d '{"tag_name":"1.0.0","draft":false,"prerelease":false}') + standardReleasePipelineWithGenericTrigger.usernamePassword({credentialsId=jenkins-github-bot-token, usernameVariable=GITHUB_USER, passwordVariable=GITHUB_TOKEN}) + standardReleasePipelineWithGenericTrigger.withCredentials([[GITHUB_USER, GITHUB_TOKEN]], groovy.lang.Closure) + standardReleasePipelineWithGenericTrigger.sh(curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer GITHUB_TOKEN' https://api.github.com/repos/Codertocat/Hello-World/releases/17372790 -d '{"tag_name":"1.0.0","draft":false,"prerelease":false}') diff --git a/vars/standardReleasePipelineWithGenericTrigger.groovy b/vars/standardReleasePipelineWithGenericTrigger.groovy index d04a2bbe1..7ddf83b31 100644 --- a/vars/standardReleasePipelineWithGenericTrigger.groovy +++ b/vars/standardReleasePipelineWithGenericTrigger.groovy @@ -48,11 +48,11 @@ void call(Map args = [:], Closure body) { regexpFilterExpression: (args.regexpFilterExpression ?: 'true') ) } - environment { - tag = "$ref" - } - stages{ - stage("Release") { + environment { + tag = "$ref" + } + stages { + stage('Release') { steps { script { body() @@ -63,18 +63,18 @@ void call(Map args = [:], Closure body) { post { success { script { - if (args.publishRelease && release_url!= null){ - withCredentials([string(credentialsId: 'jenkins-github-bot-token', variable: 'GIT_TOKEN')]){ - sh "curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer ${GIT_TOKEN}' ${release_url} -d '{\"tag_name\":\"${tag}\",\"draft\":false,\"prerelease\":false}'" - } - } + if (args.publishRelease && release_url != null) { + withCredentials([usernamePassword(credentialsId: 'jenkins-github-bot-token', usernameVariable: 'GITHUB_USER', passwordVariable: 'GITHUB_TOKEN')]) { + sh "curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer ${GITHUB_TOKEN}' ${release_url} -d '{\"tag_name\":\"${tag}\",\"draft\":false,\"prerelease\":false}'" + } + } } } always { script { postCleanup() - } } } } - } \ No newline at end of file + } +} \ No newline at end of file