【问题标题】:Jenkins mask passwords use in "Execute system Groovy script"Jenkins 掩码密码在“执行系统 ​​Groovy 脚本”中使用
【发布时间】:2017-05-19 10:13:17
【问题描述】:

我正在尝试使用“系统 Groovy 脚本”通过 jenkins 将应用程序取消部署/部署到 Tomcat。

对于取消部署/部署,我需要凭据。 这些我通过“掩码密码”(用户和密码)在詹金斯工作中掩盖了

我无法在我的“系统 Groovy 脚本”中正确使用这些变量。

当我直接在脚本中使用凭据时,它工作正常。 这是我的“系统 Groovy 脚本”:

def ant = new AntBuilder()

//def user = build.getEnvVars()['user']
//def password = build.getEnvVars()['password']


ant.taskdef( name: 'deploy', classname: 'org.apache.catalina.ant.DeployTask' )
ant.taskdef( name: 'undeploy', classname: 'org.apache.catalina.ant.UndeployTask' )

ant.undeploy(
    url:deployURL,
    username:"${user}",
    password:"${password}",
    path:deployPath,
    failonerror:true)

ant.deploy(
    url:deployURL,
    username:"${user}",
    password:"${password}",
    path:deployPath
    war:warfile)

【问题讨论】:

  • 忘记了“你好”,无法编辑它......所以我将它添加到评论中。您好,感谢您提前提供帮助。
  • 雅各布,非常感谢。这解决了我的问题。现在我可以访问保存的密码并且可以在工作中使用它。再次非常感谢您。最好的问候 - 编辑:我如何支持您的评论作为我问题的解决方案?
  • 很高兴有帮助!我认为最好的办法是对我链接的答案进行投票,并可能提供您用来适应问题的具体细节的摘要并将其发布在此处,然后接受您自己的答案。

标签: jenkins groovy


【解决方案1】:

Jenkins Credentials Store Access via Groovy

我通过以下方式使用了上面链接中的解决方案:

def credentials_store = jenkins.model.Jenkins.instance.getExtensionList(
        'com.cloudbees.plugins.credentials.SystemCredentialsProvider')

credentials_store[0].credentials.each { ThisJenkins ->
    if (ThisJenkins instanceof com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl) {
        if (ThisJenkins.username == "MyUser") {
            user = ThisJenkins.username
            password = ThisJenkins.password
        }
    }
}

后来我在部署中使用了“用户”和“密码”:

ant.undeploy(
    url:'MyServer',
    username: user,
    password: password,
    path:'/MyTool',
    failonerror:false)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多