jenkinsci / jenkinsci/credentials-binding-plugin
[JENKINS-68779] Using personal credentials in declarative Pipeline fails
- Dominant language
- Java
- Stars
- 57
- Forks
- 108
- PR merge metrics
- No merged PRs in 30d
Description
I try to use a user credential in declafative pipeline which I select via a credential parameter.
The parameter selection allows me to pick a credential which is scoped to my user.
How ever if I try later on to the selected credential in a withcredential block I get an error mo such credential. If I pick a credential wit scope global the code works.
pipeline {
agent none
tools {
jdk 'JDK 11'
maven 'Maven 3.8.4'
}
options {
buildDiscarder logRotator(
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '3',
daysToKeepStr: '',
numToKeepStr: '5')
}
parameters {
credentials credentialType: 'com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey',
name: 'DEPLOY_CRED', required: true, defaultValue: '',
description: 'The credential used on the target systems for the deployment (Username, SSH Key)'
}
stages {
stage( 'public') {
agent any
steps {
echo "Deploy monitoring on XXX as ${DEPLOY_CRED{color:#569cd6"}}
withCredentials([sshUserPrivateKey(credentialsId: DEPLOY_CRED ,
keyFileVariable: 'KEY_PATH',
usernameVariable: 'REMOTE_USER' )]) {
sh 'cp -f $KEY_PATH luckilucki.txt'
echo "${REMOTE_USER{color:#569cd6 ${KEY_PATH{color:#569cd6}}"}}
}
}
}
}
}
---
Originally reported by grafra_pass, imported from: Using personal credentials in declarative Pipeline fails
Raw content of original issue
I try to use a user credential in declafative pipeline which I select via a credential parameter.
The parameter selection allows me to pick a credential which is scoped to my user.
How ever if I try later on to the selected credential in a withcredential block I get an error mo such credential. If I pick a credential wit scope global the code works.
pipeline {
agent none
tools {
jdk 'JDK 11'
maven 'Maven 3.8.4'
}
options {
buildDiscarder logRotator(
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '3',
daysToKeepStr: '',
numToKeepStr: '5')
}parameters {
credentials credentialType: 'com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey',
name: 'DEPLOY_CRED', required: true, defaultValue: '',
description: 'The credential used on the target systems for the deployment (Username, SSH Key)'
}stages {
stage( 'public') {
agent any
steps {
echo "Deploy monitoring on XXX as ${DEPLOY_CRED{color:#569cd6"}}withCredentials([sshUserPrivateKey(credentialsId: DEPLOY_CRED ,
keyFileVariable: 'KEY_PATH',
usernameVariable: 'REMOTE_USER' )]) {
sh 'cp -f $KEY_PATH luckilucki.txt'
echo "${REMOTE_USER{color:#569cd6 ${KEY_PATH{color:#569cd6}}"}}}
}
}
}
}
Contributor guide
Assessment
This issue has not been assessed yet.