如何教我的Jenkisfile在此设置中通过基本身份验证登录?
我正在为我的Jenkins构建使用自定义docker镜像.
如文档here中所述,我定义了一个docker agent,如下所示:
pipeline {
agent {
docker {
image 'registry.az1:5043/maven-proto'
registryUrl 'https://registry.az1'
args '-v /var/jenkins_home/.m2:/root/.m2'
}
}
options {
timeout(time: 1,unit: 'HOURS')
buildDiscarder(logRotator(numToKeepStr:'10'))
}
stages {
stage ('Build') {
steps{
sh ...
}
}
stage ('Test') {
steps {
sh ...
}
}
stage ('Deploy') {
steps {
sh ...
}
}
}
post {
always {
echo 'Clean up workspace'
deleteDir()
}
}
}
如果我使用以下代理设置:
pipeline {
agent {
docker.withRegistry('https://registry.az1','registry_login'){
image 'registry.az1:5043/maven-proto'
registryUrl 'https://registry.az1'
args '-v /var/jenkins_home/.m2:/root/.m2'
}
}
管道的执行失败,出现以下异常:
WorkflowScript: 3: Too many arguments for map key "withRegistry" @ line 3,column 16.
docker.withRegistry('https://registry.az1','registry_login'){
^
WorkflowScript: 3: Invalid agent type "withRegistry" specified. Must be one of [docker,dockerfile,label,any,none] @ line 3,column 16.
docker.withRegistry('https://registry.az1','registry_login'){
^
最佳答案
如Using a custom registry中所述,您可以指定要使用的凭据和注册表URL:
原文链接:https://www.f2er.com/docker/435831.htmldocker.withRegistry('https://registry.az1','credentials-id') {
...
}
您需要创建一个Jenkins凭证对象,该对象将包含存储库的凭据,并为其替换名称以替换上面的凭证ID.
更新:
对于声明性管道,语法如下:
agent {
docker {
image 'registry.az1:5043/maven-proto'
registryUrl 'https://registry.az1'
registryCredentialsId 'credentials-id'
args '-v /var/jenkins_home/.m2:/root/.m2'
}
}