Jenkins Pipeline: how to access credentials variable??

3,998 views
Skip to first unread message

Phil Swenson

unread,
Aug 9, 2016, 3:20:17 PM8/9/16
to Jenkins Users
I am using the Jenkins Pipeline Plugin, but having trouble getting my docker config credential to do what I need.


using code like:

node('docker-slave') { 

    withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'NEXUS', usernameVariable: 'NEXUS_USERNAME', passwordVariable: 'NEXUS_PASSWORD'],
 [$class: 'FileBinding', credentialsId: 'DOCKER_REGISTRY', variable: 'DOCKER_CONFIG_PATH']]) {
        def dockerConfigPath = "$DOCKER_CONFIG_PATH"
        
        


the dockerConfigPath above does not get populated as I'd hope...



The variable DOCKER_CONFIG_PATH passes in the absolute path to the docker config file. I only need the directory path, NOT the file path. 

So if the DOCKER_CONFIG_PATH is something like /jenkins/tmp/393939kdk/config.json , I need to set the DOCKER_CONFIG environment variable to  /jenkins/tmp/393939kdk/

Given all the security stuff that's built in to the groovy script, I haven't been able to do this.

My question boils down to this:  how do I get access to the variable DOCKER_CONFIG_PATH that is pulled from the credentials.  I need to drop the filename at the end off the string.



Thanks
phil

Cyrille Le Clerc

unread,
Aug 18, 2016, 4:16:01 AM8/18/16
to Jenkins Users
Hello Phil,

The "withCredentials" step exposes the credentials as Shell Environment Variables, not as groovy variables.

Regarding Docker credentials, did you consider using the Pipeline Docker Plugin and a "docker.withRegistry(...) {}" build wrapper? You can find a sample here: https://github.com/CloudBees-community/game-of-life/blob/db105fed560ffb3f5880224d1693d72ee2e89097/Jenkinsfile#L16

Cyrille
Reply all
Reply to author
Forward
0 new messages