首页 > 解决方案 > 在 Jenkins Slave 中运行 Kaniko

问题描述

我想在 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 '''
    } 

标签: jenkinsjenkins-pipelinedevopskaniko

解决方案


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'
        }
      }
    }  
  }
}

推荐阅读