1

我想在 jenkins 中将 kaniko 作为奴隶运行。我的管道在 docker 插件上运行,我如何使用 kaniko 设置 gcr 凭据。

我想将 GCR 凭据上传到 Jenkins 主服务器。

我的管道 groovy 如下所示:

node("kaniko-jnlp") {
stage('Building Stage') {
  git 'https://github.com/jenkinsci/docker-jnlp-slave.git'

      sh ''' /kaniko/executor -f `pwd`/Dockerfile -c `pwd` --insecure- 
               skip-tls-verify --cache=true 
             --- destination=gcr.io/project/project:v1 '''
    } 
4

2 回答 2

1

I run my whole pipeline encapsulated inside a pod, here how I use Kaniko:

pipeline {
  agent {
    kubernetes {
      yaml """
apiVersion: v1
kind: Pod
metadata:
  labels:
    jenkins: worker
spec:
  containers:
  - name: kaniko
    image: gcr.io/kaniko-project/executor:debug
    command: ["/busybox/cat"]
    tty: true
    volumeMounts:
      - name: dockercred
        mountPath: /root/.docker/
  volumes:
  - name: dockercred
    secret:
      secretName: dockercred
"""
    }
  }
  stages {
    stage('Stage 1: Build with Kaniko') {
      steps {
        container('kaniko') {
          sh '/kaniko/executor --context=git://github.com/repository/project.git \
                  --destination=repository/image:tag \
                  --insecure \
                  --skip-tls-verify  \
                  -v=debug'
        }
      }
    }  
  }
}
于 2021-05-03T13:49:21.233 回答
1

我正在使用 Kaniko 构建图像并推送到私人仓库。我的 Kaniko docker 镜像使用 Kubernetespull-secret进行身份验证,但您应该能够使用以下代码:

stage('Kaniko') {
        environment {
            ARTIFACTORY_CREDS = credentials('your-credentials')
        }
        steps{
            sh "echo ********** EXAMPLE APP **********"
            container(name: 'kaniko', shell: '/busybox/sh') {
              withEnv(['PATH+EXTRA=/busybox']) {
                  sh '''#!/busybox/sh
                  /kaniko/executor --context `pwd` --cleanup --dockerfile=your/Dockerfile --build-arg ARTIFACTORY_USER=$ARTIFACTORY_CREDS_USR --build-arg ARTIFACTORY_PASS=$ARTIFACTORY_CREDS_PSW --destination=your.docker.repo/team/image:tag
                  '''
              }
            }
        }
}
于 2019-07-29T16:15:16.210 回答