jenkins - 在声明性詹金斯的阶段内并行运行
问题描述
所以,我想在一个阶段内运行我的并行阶段,但我也想通过我在并行父阶段的步骤中编写的每个并行阶段编写一些共享代码我面临的问题是并行阶段没有运行
stages {
stage('partent stage 1'){
something here
}
stage('parent stage 2') {
steps {
// common code for parallel stages
parallel {
stage ('1'){
// some shell command
}
stage('2') {
// some shell command
}
}
}
}
}
解决方案
为了执行共享代码,您可以在声明性管道之外定义变量和函数:
def foo = true
def checkFoo {
return foo
}
pipeline {
stage('parallel stage') {
parallel {
stage('stage 1') {
steps {
script {
def baz = checkFoo()
}
sh “echo ${baz}”
}
}
stage('stage 2') {
steps {
script {
def baz = checkFoo()
}
sh “echo ${baz}”
}
}
}
}
}
您还可以编写一个共享库,您可以在所有或某些工作中使用它。
我删除了我的第一个答案,因为它是纯 BS。
推荐阅读
- ruby-on-rails - RSpec:如何编写单元测试用例以接收在私有方法中引发的异常
- java - Java Spring中的单例bean并发
- angular - 如何使用其本地图像路径以角度显示图像
- reactjs - react-native init 不适用于 Windows 上的 react-native 0.57.1
- java - Jsch 文件上传被取消
- php - 动态 Html 表格生成
- android - 日历事件未显示?
- maxscript - 在 3dmax Maxscript 中,当用户隐藏某些对象时,我如何运行我的宏或函数
- r - 饼图中的可变字体颜色
- javascript - 如何获取折线图的日期标签?