在Jenkinsfile中使用私有docker注册表和Authentication

前端之家收集整理的这篇文章主要介绍了在Jenkinsfile中使用私有docker注册表和Authentication前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_404_0@

如何教我的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'){
                  ^

问题是使用的注册表需要基本的身份验证登录.注册表使用this配置在Nginx反向代理后面运行.

最佳答案
Using a custom registry中所述,您可以指定要使用的凭据和注册表URL:

docker.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'
    }
}
原文链接:https://www.f2er.com/docker/435831.html

猜你在找的Docker相关文章