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


        }
}
相关推荐
石像鬼₧魂石2 小时前
内网渗透靶场实操清单(基于 Vulhub+Metasploitable 2)
linux·windows·学习·ubuntu
橘子真甜~4 小时前
C/C++ Linux网络编程15 - 网络层IP协议
linux·网络·c++·网络协议·tcp/ip·计算机网络·网络层
拾贰_C5 小时前
【Linux | Windows | Terminal Command】 Linux---grep | Windows--- findstr
linux·运维·服务器
阿华hhh5 小时前
Linux系统编程(标准io)
linux·开发语言·c++
石像鬼₧魂石6 小时前
Kali Linux 网络端口深度扫描
linux·运维·网络
alengan6 小时前
linux上面写python3日志服务器
linux·运维·服务器
Rose sait7 小时前
【环境配置】Linux配置虚拟环境pytorch
linux·人工智能·python
叶之香8 小时前
CentOS/RHEL 7、8安装exfat和ntfs文件系统
linux·运维·centos
一世琉璃白_Y8 小时前
pg配置国内数据源安装
linux·python·postgresql·centos