jenkinsci / jenkinsci/credentials-binding-plugin

[JENKINS-68779] Using personal credentials in declarative Pipeline fails

Open
#499 0 comments 0 reactions 0 assignees View on GitHub
component:credentials-binding-plugin imported-jira-issue priority:major resolution:unresolved
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


  • status: Open
  • priority: Major
  • component(s): credentials-binding-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 1
  • imported: 20251211-141027

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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.