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"
                                        
                                }
                        }
                }


        }
}
相关推荐
ICscholar2 小时前
ExaDigiT/RAPS
linux·服务器·ubuntu·系统架构·运维开发
sim20202 小时前
systemctl isolate graphical.target命令不能随便敲
linux·mysql
米高梅狮子2 小时前
4. Linux 进程调度管理
linux·运维·服务器
再创世纪3 小时前
让USB打印机变网络打印机,秀才USB打印服务器
linux·运维·网络
fengyehongWorld4 小时前
Linux ssh端口转发
linux·ssh
知识分享小能手5 小时前
Ubuntu入门学习教程,从入门到精通, Ubuntu 22.04中的Shell编程详细知识点(含案例代码)(17)
linux·学习·ubuntu
Xの哲學6 小时前
深入解析 Linux systemd: 现代初始化系统的设计与实现
linux·服务器·网络·算法·边缘计算
龙月7 小时前
journalctl命令以及参数详解
linux·运维
EndingCoder7 小时前
TypeScript 的基本类型:数字、字符串和布尔
linux·ubuntu·typescript
YJlio8 小时前
Kali Linux 外置无线网卡接入与识别排障(VMware 环境|合规学习版)
linux·网络·学习