2

我想在我的 jenkins 脚本(groovy)文件中使用 Kaniko 来构建图像。

我的 jenkins 中没有其他配置,我只想使用我的 jenkins 脚本

脚本如下所示:

podTemplate(label: 'jenkins-kaniko',
    containers:[
    containerTemplate(name: 'kaniko', image: 'gcr.io/kaniko-project/executor:debug', command: '/busybox/cat', ttyEnabled: true)
    ],
    volumes: [
                secretVolume(mountPath: '/home/jenkins/.aws/',  secretName: 'aws-secret'),
                configMapVolume(mountPath: '/kaniko/.docker/', configMapName: 'docker-config')
                
    ])

{
    node ('jenkins-kaniko') {

    environment {
        registry = ""
        registryCredential = ''
        imageName = 'jenkins_slave'
        dockerImage = ''
        //dockerHome = tool 'docker_latest'
        //PATH = "$dockerHome/bin:$PATH"
    }
   
    stages {
      stage('Prepare') {
                steps {
                    echo "CheckOut"
                    script {
                        //here is checkout git code
                    }
                   
                }
            }
       stage('Building image') {
/*            agent {
                label 'jenkinskaniko'
            }
  */          
             steps {
                dir('jenkins-slave'){
            
                echo 'build image'
                container('kaniko'){
                sh "/kaniko/executor --dockerfile `pwd`/Dockerfile `pwd` --insecure --skip-tls-verify --cache=true --destination= jenkins_slave:${env.BUILD_ID}"
                }
                } 
            
            }
            
           
        
               
        }
    
        stage('Deploy Image'){
                steps {
                    script {
                       docker.withRegistry(registry) {
                           dockerImage.push()
                       } 
                    }
                }
        }
    }
    }
}

但我已经尝试了几次并得到了这个错误:

创建的 Pod:kubernetes crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk [警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。[警告][crpcc-jenkins-prodslaves/jenkins-kaniko-hrfk9-j06mk][FailedScheduling] 0/33 个节点可用:33 个节点与节点选择器不匹配。

任何解决方案?

4

1 回答 1

0

你能试试下面的脚本吗:

def label = "goweb-1.$BUILD_NUMBER-pipeline"
 
podTemplate(label: label, containers: [
 containerTemplate(name: 'kaniko', image: 'gcr.io/kaniko-project/executor:debug', command: '/busybox/cat', ttyEnabled: true)
],
volumes: [
   secretVolume(mountPath: '/root/.docker/', secretName: 'dockercred')
]) {
 node(label) {
   stage('Stage 1: Build with Kaniko') {
     container('kaniko') {
       sh '/kaniko/executor --context=git://github.com/repository/project.git \
               --destination=docker.io/repository/image:tag \
               --insecure \
               --skip-tls-verify  \
               -v=debug'
     }
   }
 }
}
于 2021-05-03T13:56:14.577 回答