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


        }
}
相关推荐
tedcloud1231 小时前
OpenShip 部署指南:开源 AI 应用快速启动模板 Linux 搭建实践
linux·运维·服务器·人工智能·开源
菜地里的小菜鸟7 小时前
将linux程序打成.run包
linux·将linux程序打成run包·运维自动安装包
晚风吹长发10 小时前
Docker基础——Docker Network(网络详解)
linux·运维·网络·ubuntu·docker·容器
高磊200512 小时前
LVS(Linux virual server)
linux·服务器·lvs
shwill12312 小时前
PID 算法(三)--- 增量 PID ↔ 单神经元 PID 等价映射
linux·算法
执笔画流年呀13 小时前
Linux搭建Java项目部署环境
java·linux·运维
Sisphusssss14 小时前
香橙派5plus GPIO
linux·python·ubuntu
W.W.H.14 小时前
嵌入式 Linux外接USB/WIFI模块兼容5G频段实战
linux·运维·5g·wifi
影视飓风TIM14 小时前
Linux下C程序编译:gcc 动态链接与静态链接全解
linux·c语言
ji_shuke15 小时前
从零深入:基于 Playwright + Pytest + Allure 的企业级 Web 端到端自动化测试框架实战
前端·自动化测试·docker·jenkins·pytest·allure·playwright