jenkins - 在 Jenkins 管道的各个阶段之间传输数据

标签 jenkins jenkins-pipeline pipeline

我能否以某种方式从一个阶段复制数据以供在另一个阶段使用?

例如,我有一个阶段想要克隆我的存储库,而在另一个阶段运行 Kaniko,它将(在 dockerfile 上)所有数据复制到容器并构建它

如何做到这一点?因为

  • 阶段是独立的,我无法在两个阶段通过相同的数据进行操作
  • 在 Kaniko 上,我无法安装 GIT 以将其克隆到那里 提前致谢

代码示例:

pipeline {
  agent none
  stages {
    stage('Clone repository') {
      agent {
        label 'builder'
      }
      steps {
        sh 'git clone ssh://git@myrepo.com./repo.git'
        sh 'cd repo'
      }
    }
    stage('Build application') {
      agent {
        docker {
          label 'builder'
          image 'gcr.io/kaniko-project/executor:debug'
          args '-u 0 --entrypoint=""'
        }
      }
      steps {
        sh '''#!/busybox/sh
          /kaniko/executor -c `pwd` -f Dockerfile"
        '''
      }
    }
  }
}

附言在 dockerfile 上我使用诸如

ADD . /

最佳答案

你可以尝试使用stash :

stage('Clone repository') {
  agent {
    label 'builder'
  }
  steps {
    sh 'git clone ssh://git@myrepo.com./repo.git'
    script {
      stash includes: 'repo/', name: 'myrepo'
    }
  }
}
stage('Build application') {
  agent {
    docker {
      label 'builder'
      image 'gcr.io/kaniko-project/executor:debug'
      args '-u 0 --entrypoint=""'
    }
  }
  steps {
    script {
      unstash 'myrepo'
    }
    sh '''#!/busybox/sh
      /kaniko/executor -c `pwd` -f Dockerfile"
    '''
  }

关于jenkins - 在 Jenkins 管道的各个阶段之间传输数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67532771/

相关文章:

tomcat - 如何通过 scp 插件从 Jenkins 访问远程主机上的/var/lib/tomcat6/webapps

java - 获取 404 虽然我的应用程序已部署

jenkins - 在 Jenkinsfile 中创建时间戳

ruby-on-rails - Heroku 上的 Rails - 站点未加载 - ActionView::Template::Error( Assets 管道中不存在 Assets "image.jpg"。)

c# - 在Gstreamer(C#)中使用管道播放音频

scala - 如何从 CrossValidatorModel 中提取最佳参数

shell - 当通过 Jenkins 管道中的 shell 脚本运行 ansible playbook 时,回显输出被缓冲并且不会实时显示

node.js - Jenkins 构建问题 - npm ERR!您的缓存文件夹包含根拥有的文件

jenkins - 是否保证 Jenkins 管道中的所有阶段都将在同一主机上执行?

amazon-web-services - Jenkins 管道 - 检查 ECS 服务是否存在