read the output of a secret text file

时间:2018-02-01 18:33:49

标签: jenkins jenkins-plugins jenkins-pipeline

I have the same credentials I need to inject in two different ways for different commands. As raw text and as a file path to a json file.

Im trying to do this but it does not work:

GOOGLE_APPLICATION_CREDENTIALS = credentials('myjsonkey')
GOOGLE_CREDENTIALS = "${new File( credentials('myjsonkey') ).text}"

1 个答案:

答案 0 :(得分:1)

在管道中,必须像这样访问秘密文件

withCredentials([file(credentialsId: 'pets-id', variable: 'mySecretFile')]) {
    // some block can be a groovy block as well and the variable will be available to the groovy script
    sh '''
         echo "This is the directory of the secret file $mySecretFile"
         echo "This is the content of the file `cat $mySecretFile`"
       '''
}

'pets-id'是我给凭证的ID。