“pega_db_password”的类型为“Username with password”,其中应为“org.jenkinsci.plugins.plaincredentials.StringCredentials”

5tmbdcev  于 2023-03-29  发布在  Jenkins
关注(0)|答案(1)|浏览(161)

我正在看一个从Jenkins Credentials插件阅读隐藏密码的例子,我试图做这个快速的例子,看看我现在如何在我的脚本中使用它。

'pega_db_password' is of type 'Username with password' where 'org.jenkinsci.plugins.plaincredentials.StringCredentials' was expected

脚本如下:

withCredentials([string(credentialsId: 'pega_db_password', variable: 'pega_db_password')]) {
        sh 'echo $pega_db_password'
      
      }

设置为

我已经试着研究这个问题,但无法解决这个问题。我真的需要使用这个只是把密码放在节点代理内部的一个文件中。

vsaztqbk

vsaztqbk1#

需要进行2项变更:

1.请勾选用户名保密复选框
**2.**修改管道脚本如下:

withCredentials([usernamePassword(credentialsId: 'pega_db_password', usernameVariable: 'PEGA_DB_USERNAME', passwordVariable: 'PEGA_DB_PASSWORD')]) {
    sh 'echo $PEGA_DB_PASSWORD' // warning will be thrown by jenkins
  
  }

Jenkins的凭证插件的其他示例可以在here中找到。

相关问题