将密码作为环境变量注入到构建中 [英] Inject passwords to the build as environment variables

查看:193
本文介绍了将密码作为环境变量注入到构建中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过构建环境"部分中的选项在jenkins中设置密码,该选项可在我的测试中用于获取和使用密码.这是我正在检查将密码作为环境变量注入到内部版本"的选项.问题是种子作业运行后,我将失去这些值.因此,我的附加值在种子作业运行后消失了.有人遇到过这个问题吗?如何使其永久化,以便每次我都可以在测试代码中检索到这些pwds时?

I am trying to set a password in jenkins through an option in 'build environments' section which can be used in my test to get the password and use it. This is the option i am checking in "Inject passwords to the build as environment variables". Problem is i am loosing these values once the seed job runs. So my values added are disappearing after seed job runs. Did anybody faced this problem? How to make it permanent so every time i can retrieve those pwds in my test code?

推荐答案

@daspilker,@JesseGlick,非常感谢您的答复.它帮助我用Jenkins编写了我的第一个configure块.提及我的行为,以便对其他面临相同问题的人有所帮助.

@daspilker , @JesseGlick, Thank you very much for your responses. It helped me to write my first configure block in Jenkins. Mentioning my actions so for others facing same problem might help.

由于我们使用的是Job DSL 1.27,因此我无法直接使用凭据绑定.因此创建了一个configure块,并通过.groovy脚本注入了所需的变量.

Since we are using Job DSL 1.27, I am not able to use credentials-Binding directly. So created a configure block and injected required variables through my .groovy script.

注意:如果收到找不到credentialsId"错误,则需要从'*****/job/config.xml中获取'credentialsId'的转换值.

Note: You need to take the converted value for 'credentialsId' from '*****/job/config.xml if you are getting "credentialsId did not found" error.

static def credentialsBinding = { String userNameVar, String passwordVar, String credId, wrapperContext ->
    def nodeBuilder = new NodeBuilder()
    wrapperContext.wrapperNodes << nodeBuilder.'org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper'(plugin: "credentials-binding@1.4") {
        bindings {
            'org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding' {
                usernameVariable userNameVar
                passwordVariable passwordVar
                credentialsId credId
            }
        }
    }
}

这篇关于将密码作为环境变量注入到构建中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆