pipeline 多個參數如何傳入


1.准備一個json文件

{
 
   "NAME" : "Lucy",
 
   "AGE" : "18",
 
   "PHONE_NUMBER" : "13912345678",
 
   "ADDRESS" : "Haidian Beijing",
 
   "EMAIL" : "lucy@demo.com",
 
   "GENDER" : "male",
 
   "IS_MARRY" : false
 
}

/tmp/Anthony/test.json寫入上面的內容,保存,這個路徑下面會用到

2.修改job成參數化構建

 

 

 

 3.groovy代碼

import hudson.model.*;
 
 
pipeline{
 
   agent any
   stages{
      stage("Hello Pipeline") {
         steps {
             script {
                println "Hello Pipeline!"
                println env.JOB_NAME
                println env.BUILD_NUMBER
            }
         }
      }
 
      stage("Init paramters in json") {
         steps {
             script {
 
                println "read josn input file"
                json_file = INPUT_JSON? INPUT_JSON.trim() : ""
                prop = readJSON file : json_file
                name = prop.NAME? prop.NAME.trim() : ""
                println "Name:" + name
            }
         }
      }
   }
 
}

 

4.調試

 

 

如果提示報錯,沒有readJSON方法,說明你jenkins環境沒有安裝插件:Utility Steps, 去插件管理中搜索並安裝這個。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM