读取秘密文本文件的输出

red*_*888 3 jenkins jenkins-plugins jenkins-pipeline

我有相同的凭据,需要以两种不同的方式为不同的命令注入。作为原始文本和 json 文件的文件路径。

我试图这样做,但它不起作用:

GOOGLE_APPLICATION_CREDENTIALS = credentials('myjsonkey')
GOOGLE_CREDENTIALS = "${new File( credentials('myjsonkey') ).text}"
Run Code Online (Sandbox Code Playgroud)

OK9*_*999 5

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

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`"
       '''
}
Run Code Online (Sandbox Code Playgroud)

“pets-id”是我为凭证提供的 ID。

  • 我怀疑是否有一个函数调用credentials()。你从哪里得到的? (2认同)
  • credentials() 是将指定凭证绑定到声明式管道语法中的环境变量的语法:https://jenkins.io/doc/book/pipeline/syntax/#environment (2认同)