0

我试图让以下功能在 Jenkins 的声明式管道语法中工作:

  • 仅在master分支上条件执行某些阶段
  • input要求用户确认以部署到暂存环境
  • 在等待确认时,它不会阻止执行者

这是我最终得到的结果:

pipeline {
  agent none
  stages {
    stage('1. Compile') {
      agent any
      steps {
        echo 'compile'
      }
    }
    stage('2. Build & push Docker image') {
      agent any
      when {
        branch 'master'
      }
      steps {
        echo "build & push docker image"
      }
    }
    stage('3. Deploy to stage') {
      when {
        branch 'master'
      }
      input {
        message "Deploy to stage?"
        ok "Deploy"
      }
      agent any
      steps {
        echo 'Deploy to stage'
      }
    }
  }
}

问题是阶段 2 需要来自 1 的输出,但在运行时不可用。如果我用agentglobal 替换各种指令agent any,则输出可用,但执行程序在第 3 阶段被阻止等待用户输入。如果我尝试将 1 和 2 组合成一个阶段,那么我将失去有条件的能力仅在master.

有没有办法实现我正在寻找的所有行为?

4

1 回答 1

1

You need to use the stash command at the end of your first step and then unstash when you need the files

I think these are available in the snippet generator

As per the documentation

Saves a set of files for use later in the same build, generally on another node/workspace. Stashed files are not otherwise available and are generally discarded at the end of the build. Note that the stash and unstash steps are designed for use with small files. For large data transfers, use the External Workspace Manager plugin, or use an external repository manager such as Nexus or Artifactory

于 2018-05-18T21:58:36.050 回答