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


        }
}
相关推荐
hugerat9 小时前
在AI的帮助下,用C++构造微型http server
linux·c++·人工智能·http·嵌入式·嵌入式linux
ha204289419410 小时前
Linux操作系统学习记录之----自定义协议(网络计算器)
linux·网络·学习
想唱rap10 小时前
MYSQL在ubuntu下的安装
linux·数据库·mysql·ubuntu
糖~醋排骨10 小时前
DHCP服务的搭建
linux·服务器·网络
dust_and_stars10 小时前
ubuntu24使用apt安装VS-code-server code-server
linux·服务器·windows
码农小韩11 小时前
基于Linux的C++学习——循环
linux·c语言·开发语言·c++·算法
ling-4511 小时前
Linux-day09 11
linux·运维·服务器
202321336054 刘11 小时前
Linux常用命令分类整理
linux·运维·数据库
南工孙冬梅11 小时前
【久久派】 新世界系统安装
linux
zbguolei11 小时前
Debian提示:“用户名” 不是 sudoers 文件
linux·服务器·debian