【问题标题】:how do i add authentication credentials to docker pipeline in jenkins?如何在 jenkins 中向 docker 管道添加身份验证凭据?
【发布时间】:2020-05-23 08:47:54
【问题描述】:

我熟悉如何使用 docker 管道在 jenkins 上的 docker 容器中运行作业,但到目前为止,它非常适用于不需要任何身份验证凭据从注册表中提取图像的公共 docker 图像

https://jenkins.io/doc/book/pipeline/docker/

比如说我有这个例子

pipeline {
    agent {
        docker { 
                 image 'private.docker.local/node:7-alpine' 
                 args '--net=host  -u root'
               }
    }
    stages {
        stage('Test') {
            steps {
                sh 'node --version'
            }
        }
    }
}

当我尝试时我得到错误

+ docker pull private.docker.local/node:7-alpine

Error response from daemon: Get https://private.docker.local/v2/node:7-alpine/manifests/7-alpine: denied: access forbidden

有人知道如何添加身份验证,以便 docker 管道可以登录到 docker 注册表以提取图像吗?

【问题讨论】:

    标签: jenkins docker-registry jenkins-job-dsl


    【解决方案1】:

    其实终于在这里找到答案https://jenkins.io/doc/book/pipeline/syntax/#agent

    pipeline {
        agent {
            docker { 
                     alwaysPull true
                     image 'private.docker.local/node:7-alpine' 
                     args '--net=host  -u root'
                     registryUrl 'https://private.docker.local/'
                     registryCredentialsId 'registry-credential'
                   }
        }
        stages {
            stage('Test') {
                steps {
                    sh 'node --version'
                }
            }
        }
    }
    

    享受

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-26
      • 2013-04-11
      • 1970-01-01
      • 2017-11-04
      • 1970-01-01
      相关资源
      最近更新 更多