[英]How to use Random number in Jenkins Declarative pipeline
有人可以幫我如何在 jenkins 聲明性管道中使用隨機數作為環境變量,以便在整個管道中使用這個數字,我們需要這個數字作為我的構建工件的標簽。 謝謝你。
我在我的 Jenkins 聲明性管道中嘗試了下面,但它拋出了 null 消息
environment {
rand = "$RANDOM"
}
stages{
stage("number"){
steps{
script{
echo " this is a number $rand"
}}}}
這是管道腳本,用於生成隨機數:
pipeline {
agent any
environment {
max = 50
random_num = "${Math.abs(new Random().nextInt(max+1))}"
}
stages {
stage('Randon number') {
steps {
echo "The random number is: ${env.random_num}"
}
}
}
}
這將生成 0-50 之間的隨機數。
在這里您可以更改max
的值來決定上限范圍。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.