小编典典

将密码作为环境变量注入到构建中

jenkins

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


阅读 317

收藏
2020-07-25

共1个答案

小编典典

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

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

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

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
            }
        }
    }
}
2020-07-25