gpt4 book ai didi

jenkins - Jenkins:在全局环境部分中使用withCredentials

转载 作者:行者123 更新时间:2023-12-04 12:16:41 29 4
gpt4 key购买 nike

我有一个包含多个阶段的Jenkins管道,每个阶段都需要相同的环境变量,我这样运行:

script {
withCredentials([usernamePassword(credentialsId: 'COMPOSER_REPO_MAGENTO', passwordVariable: 'MAGE_REPO_PASS', usernameVariable: 'MAGE_REPO_USER')]) {
def composerAuth = """{
"http-basic": {
"repo.magento.com": {
"username": "${MAGE_REPO_USER}",
"password": "${MAGE_REPO_PASS}"
}
}
}""";
// do some stuff here that uses composerAuth
}
}


我不想每次都不必重新声明 composerAuth,所以我想将凭据存储在全局变量中,因此可以执行以下操作:

script {
// do some stuff here that uses global set composerAuth
}


我尝试将其放在环境部分中:

environment {
DOCKER_IMAGE_NAME = "magento2_website_sibo"
withCredentials([usernamePassword(credentialsId: 'COMPOSER_REPO_MAGENTO', passwordVariable: 'MAGE_REPO_PASS', usernameVariable: 'MAGE_REPO_USER')]) {
COMPOSER_AUTH = """{
"http-basic": {
"repo.magento.com": {
"username": "${MAGE_REPO_USER}",
"password": "${MAGE_REPO_PASS}"
}
}
}""";
}
}


但是(像我这样时髦的菜鸟)不起作用。那么用凭证设置全局可访问变量但只需要声明一次的最佳方法是什么?

最佳答案

您可以使用credentials部分的environment帮助器方法。对于“用户名和密码”类型的凭据,它分配2个其他环境变量。例:

environment {
MAGE_REPO_CREDENTIALS = credentials('COMPOSER_REPO_MAGENTO')
COMPOSER_AUTH = """{
"http-basic": {
"repo.magento.com": {
"username": "${env.MAGE_REPO_CREDENTIALS_USR}",
"password": "${env.MAGE_REPO_CREDENTIALS_PSW}"
}
}
}"""
}

Read more

关于jenkins - Jenkins:在全局环境部分中使用withCredentials,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48182807/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com