【问题标题】:How to insert properties in Jenkinsfile in multibranch pipeline?如何在多分支管道中的 Jenkinsfile 中插入属性?
【发布时间】:2017-11-06 14:17:15
【问题描述】:

我在 Jenkins 版本 2.60.2 上配置了 jenkins 多分支管道 我正在寻找一种将我的密码保存在 jenkins 多分支管道配置中的方法,因此 Jenkinsfile 可以将它们作为执行其阶段的参数。有没有办法在詹金斯 UI 中设置这些属性? 我发现了一个类似的问题here,但我认为有一种更优选的方式。 谢谢

【问题讨论】:

  • 不清楚您的问题是什么。你实际上想要完成什么?听起来您想将秘密注入您的Jenkinsfile,而Credentials PluginCredentials Binding Plugin 是实现这一目标的事实上的方式。还有关于这种方法的 CloudBees 文档。
  • 您能否在回答我的问题时提及这些插件。我会接受的。我的问题是关于使用什么插件。谢谢。

标签: jenkins jenkins-pipeline multibranch-pipeline


【解决方案1】:

对于在 Jenkins 流水线中使用凭据,我认为有几个插件本质上是 Jenkins 核心的一部分(即使它们是插件):

这些可以结合起来为您提供一种管理凭据的方法,并提供在作业中使用它们的方法。在这些提供凭证类型实现的基础上构建了其他插件。例如,SSH Credentials Plugin 允许您在 Jenkins 中存储 SSH 凭据。

凭据绑定插件提供withCredentials 步骤。 documentation has some examples on how you could use it。这是文档中的一个示例:

node {
  withCredentials(
      [
          usernameColonPassword(
              credentialsId: 'mylogin', 
              variable: 'USERPASS'
          )
      ]
  ) {
    sh '''
          set +x
          curl -u $USERPASS https://private.server/ > output
        '''
  }
}

【讨论】:

    猜你喜欢
    • 2022-01-26
    • 2021-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多