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 小时前
Ubuntu Linux Cursor 安装与使用一
linux·运维·ubuntu
一位摩羯座DBA4 小时前
Redhat&Centos挂载镜像
linux·运维·centos
学习3人组4 小时前
CentOS配置网络
linux·网络·centos
weixin_307779134 小时前
Hive集群之间迁移的Linux Shell脚本
大数据·linux·hive·bash·迁移学习
漫步企鹅5 小时前
【蓝牙】Linux Qt4查看已经配对的蓝牙信息
linux·qt·蓝牙·配对
cui_win5 小时前
【网络】Linux 内核优化实战 - net.core.flow_limit_table_len
linux·运维·网络
梦在深巷、5 小时前
MySQL/MariaDB数据库主从复制之基于二进制日志的方式
linux·数据库·mysql·mariadb
冰橙子id5 小时前
linux系统安全
linux·安全·系统安全
stark张宇6 小时前
VMware 虚拟机装 Linux Centos 7.9 保姆级教程(附资源包)
linux·后端
Johny_Zhao6 小时前
Ubuntu系统安装部署Pandawiki智能知识库
linux·mysql·网络安全·信息安全·云计算·shell·yum源·系统运维·itsm·pandawiki