如何在Jenkinsfile脚本化管道中将凭据定义为参数

kupeojn6  于 2022-11-02  发布在  Jenkins
关注(0)|答案(2)|浏览(206)

我正在定义一个带有许多输入的脚本化管道,其中两个是凭据。在UI中,我可以看到如何添加作为凭据的输入,但我找不到有关如何为脚本化管道定义凭据参数的任何信息。我的参数定义如下:

properties([
  buildDiscarder(logRotator(numToKeepStr: '20')),
  parameters([
     stringParam(name: 'export_credentials'),
     stringParam(name: 'import_credentials'),
  ]),
])

但我更希望它是实际的凭据参数,而不是字符串参数

70gysomp

70gysomp1#

要确保字符串的安全,请使用以下方法:

properties([
   buildDiscarder(logRotator(numToKeepStr: '20')),
   parameters([
       password(description: 'b', name: 'b')
   ])
])
zlwx9yxi

zlwx9yxi2#

在研究了job-dsl插件API(/plugin/job-dsl/api-viewer/index.htm)之后,我发现了这<jenkins_url>一点:

properties([
  buildDiscarder(logRotator(numToKeepStr: '20')),
  disableResume(),
  parameters([
     credentials(name: 'export_token_credential_id', required: true, credentialType: "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl", defaultValue: 'dockerjenkins-token', description: 'Username and API Token for the Jenkins to migrate from'),
     credentials(name: 'import_token_credential_id', required: true, credentialType: "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl", defaultValue: 'cloudbees-token', description: 'Username and API Token for this Jenkins'),
     stringParam(name: 'item', description: 'Item (job) to migrate. '),
     choiceParam(name: 'disable_mode', choices: "NEITHER\nDEST\nSOURCE\nBOTH", description: 'Which Jenkins, if any, to disable jobs on when migrating'),
  ]),
])

相关问题