Skip to content

Commit

Permalink
Fix credential type for github bot (#26)
Browse files Browse the repository at this point in the history
* Fix credential type for github bot

Signed-off-by: Sayali Gaikawad <[email protected]>
  • Loading branch information
gaiksaya authored Nov 2, 2022
1 parent ecf3db7 commit 0dc9a83
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}'"))

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
24 changes: 12 additions & 12 deletions vars/standardReleasePipelineWithGenericTrigger.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
}
}
}
}
}
}
}

0 comments on commit 0dc9a83

Please sign in to comment.