我正在使用 jib Gradle 插件创建一个 docker 映像并将其推送到 Azure Container Registry。到目前为止,我已经向 Jenkins 添加了用户名/密码凭据,需要将它们传递给 Gradle。访问凭据或将凭据传递给 Gradle,它们会被屏蔽。希望您能够帮助我。以下是代码片段:
build.gradle(jib 配置):
jib {
to {
image = "myacr.azurecr.io/" + project.name
tags = ["latest"]
auth {
// retrieve from Jenkins
username System.properties['ACR_CREDENTIALS_USR']
password System.properties['ACR_CREDENTIALS_PSW']
}
}
container {
jvmFlags = ["-Xms512M", "-Xmx1G"]
ports = ["5000/tcp", "8080/tcp"]
}
}
詹金斯文件:
pipeline {
...
environment {
ACR_CREDENTIALS = credentials('myproject-acr')
}
stages {
...
stage('Push Docker Image to Registry') {
steps {
sh "./gradlew jib -PACR_CREDENTIALS_USR=${env.ACR_CREDENTIALS_USR} -PACR_CREDENTIALS_PSW=${env.ACR_CREDENTIALS_PSW}"
}
}
...
编辑:我的用户名有错字