Jenkins多stage共享同一变量方式

在第一个stage中为这个变量赋值,在其它stage中使用这个变量

groovy 复制代码
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
import groovy.json.JsonOutput
import groovy.json.JsonSlurper

// 共享的变量
def START_TIME

pipeline {
        agent {
                label "28"
        }


        stages {
                // 第一个stage里边赋值
                stage('1th stage') {
                    steps {
                        
                        script{
                            START_TIME = new Date().format("yyyy-MM-dd_HH-mm-ss", TimeZone.getTimeZone("UTC"))
                            echo "${START_TIME}"
                        }
                    }
                }
                
                // 第二个stage里边也能使用
                stage('Create Timestamped File') {
                        steps {
                                script {
                                        
                                        echo "${START_TIME}"
                                        sh "pwd"
                                        sh "touch ./x${START_TIME}x.txt"
                                        sh "ls -a"
                                        
                                }
                        }
                }


        }
}
相关推荐
自由的好好干活13 分钟前
UBI镜像文件打包与编辑
linux·嵌入式硬件
shawnyz39 分钟前
RHCSE--ansible1-入门和模块
linux·运维·ansible
奔跑的花短裤1 小时前
ubuntu安装Isaac sim4.5与强化学习使用
linux·ubuntu·机器人·强化学习·isaac sim·isaac lab
陕西小伙伴网络科技有限公司1 小时前
CentOS-7 编译glibc-2.29
linux·运维·centos
宴之敖者、2 小时前
Linux——指令
linux·运维·服务器
Xの哲學3 小时前
Linux设备驱动模型深度解剖: 从设计哲学到实战演练
linux·服务器·网络·算法·边缘计算
松涛和鸣3 小时前
DAY55 Getting Started with ARM and IMX6ULL
linux·服务器·网络·arm开发·数据库·html
HIT_Weston4 小时前
101、【Ubuntu】【Hugo】搭建私人博客:元信息&翻译(二)
linux·运维·ubuntu
暮云星影4 小时前
一、linux系统 应用开发:基本认知概念
linux·arm开发
赵民勇4 小时前
yum命令用法与技巧总结
linux·centos