Jenkins:如何使用shell脚本从构建步骤中读取jenkins凭据参数作为username:password

c0vxltue  于 2023-10-17  发布在  Jenkins
关注(0)|答案(1)|浏览(228)

我有一个Jenkins Freestyle项目。
我正在传递build-parameters,其中一个是credentials-parameter(nexus_credentials)。
我需要使用curl命令和-u选项,该选项将从运行构建时传递的参数中提取username:password
我试过:

curl --fail -u ${nexus_credentials} --upload-file "{$zipefile,$zipfile.md5,$zipfile.sha1,$zipfile.sha256,$zipfile.sha512}" "${nexus_snapshot}${version}-SNAPSHOT/"

但在日志中,我可以看到它要求密码,而不是获得,它给出错误,畸形的curl命令
我还尝试使用groovy脚本添加一个构建步骤,以用途:

withCredentials([usernameColonPassword(credentialsId: '${params.nexus_credentials}', variable: 'USERPASS')]) {
    sh 'curl --fail -u ${USERPASS} --upload-file "{\$zipefile,\$zipfile.md5,\$zipfile.sha1,\$zipfile.sha256,\$zipfile.sha512}" ${params.nexus_snapshot}\$version-SNAPSHOT/'
}

但这一个给出了错误:

Caught: groovy.lang.MissingMethodException: No signature of method: hudson10594635387748485133.usernameColonPassword() is applicable for argument types: (LinkedHashMap) values: [[credentialsId:${params.nexus_credentials}, variable:USERPASS]]
groovy.lang.MissingMethodException: No signature of method: hudson10594635387748485133.usernameColonPassword() is applicable for argument types: (LinkedHashMap) values: [[credentialsId:${params.nexus_credentials}, variable:USERPASS]]
    at hudson10594635387748485133.run(hudson10594635387748485133.groovy:1)
Build step 'Execute Groovy script' marked build as failure

如何获取用户名和密码?

mccptt67

mccptt671#

在第一个命令中尝试

curl --fail -u ${nexus_credentials_USR}:${nexus_credentials_PSW} --upload-file ...

相关问题