ci: use the credentials-binding plugin for the GitHub API Token

The standard credentials() function does not seem to do what we need. So
use the credentials-binding Jenkins plugin instead.

See-also: https://www.jenkins.io/doc/pipeline/steps/credentials-binding/
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-10-19 12:52:16 +02:00 committed by mergify[bot]
parent a6ca8e31dc
commit ed671ec207
3 changed files with 63 additions and 69 deletions

View File

@ -16,11 +16,6 @@ def ssh(cmd) {
sh "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${CICO_NODE} \"${cmd}\"" sh "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${CICO_NODE} \"${cmd}\""
} }
environment {
// "github-api-token" is a secret text credential configured in Jenkins
GITHUB_API_TOKEN = credentials("github-api-token")
}
node('cico-workspace') { node('cico-workspace') {
stage('checkout ci repository') { stage('checkout ci repository') {
git url: "${ci_git_repo}", git url: "${ci_git_repo}",
@ -28,6 +23,8 @@ node('cico-workspace') {
changelog: false changelog: false
} }
// "github-api-token" is a secret text credential configured in Jenkins
withCredentials([string(credentialsId: 'github-api-token', variable: 'GITHUB_API_TOKEN')]) {
stage('skip ci/skip/e2e label') { stage('skip ci/skip/e2e label') {
if (params.ghprbPullId == null) { if (params.ghprbPullId == null) {
skip_e2e = 1 skip_e2e = 1
@ -50,6 +47,7 @@ node('cico-workspace') {
returnStdout: true).trim() returnStdout: true).trim()
echo "detected Kubernetes patch release: ${k8s_release}" echo "detected Kubernetes patch release: ${k8s_release}"
} }
}
stage('checkout PR') { stage('checkout PR') {
if (params.ghprbPullId != null) { if (params.ghprbPullId != null) {

View File

@ -13,11 +13,6 @@ def ssh(cmd) {
sh "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${CICO_NODE} '${cmd}'" sh "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${CICO_NODE} '${cmd}'"
} }
environment {
// "github-api-token" is a secret text credential configured in Jenkins
GITHUB_API_TOKEN = credentials("github-api-token")
}
node('cico-workspace') { node('cico-workspace') {
stage('checkout ci repository') { stage('checkout ci repository') {
git url: "${ci_git_repo}", git url: "${ci_git_repo}",
@ -25,6 +20,8 @@ node('cico-workspace') {
changelog: false changelog: false
} }
// "github-api-token" is a secret text credential configured in Jenkins
withCredentials([string(credentialsId: 'github-api-token', variable: 'GITHUB_API_TOKEN')]) {
stage('skip ci/skip/e2e label') { stage('skip ci/skip/e2e label') {
if (params.ghprbPullId == null) { if (params.ghprbPullId == null) {
skip_e2e = 1 skip_e2e = 1
@ -47,6 +44,7 @@ node('cico-workspace') {
returnStdout: true).trim() returnStdout: true).trim()
echo "detected Kubernetes patch release: ${k8s_release}" echo "detected Kubernetes patch release: ${k8s_release}"
} }
}
stage('checkout PR') { stage('checkout PR') {
if (params.ghprbPullId != null) { if (params.ghprbPullId != null) {

View File

@ -14,17 +14,14 @@ def ssh(cmd) {
} }
node('cico-workspace') { node('cico-workspace') {
environment {
// "github-api-token" is a secret text credential configured in Jenkins
GITHUB_API_TOKEN = credentials("github-api-token")
}
stage('checkout ci repository') { stage('checkout ci repository') {
git url: "${ci_git_repo}", git url: "${ci_git_repo}",
branch: "${ci_git_branch}", branch: "${ci_git_branch}",
changelog: false changelog: false
} }
// "github-api-token" is a secret text credential configured in Jenkins
withCredentials([string(credentialsId: 'github-api-token', variable: 'GITHUB_API_TOKEN')]) {
stage('skip ci/skip/e2e label') { stage('skip ci/skip/e2e label') {
if (params.ghprbPullId == null) { if (params.ghprbPullId == null) {
skip_e2e = 1 skip_e2e = 1
@ -47,6 +44,7 @@ node('cico-workspace') {
returnStdout: true).trim() returnStdout: true).trim()
echo "detected Kubernetes patch release: ${k8s_release}" echo "detected Kubernetes patch release: ${k8s_release}"
} }
}
stage('checkout PR') { stage('checkout PR') {
if (params.ghprbPullId != null) { if (params.ghprbPullId != null) {