1. Prepare a json file
{ "NAME" : "Lucy", "AGE" : "18", "PHONE_NUMBER" : "13912345678", "ADDRESS" : "Haidian Beijing", "EMAIL" : "[email protected]", "GENDER" : "male", "IS_MARRY" : false }
/tmp/Anthony/test.json write to the above, save, this path will be used below
2. Modify the job parameters to construct
3.groovy Code
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. Debugging
If you are prompted an error, no readJSON way to show that you do not install the plug-jenkins environment: Utility Steps, to search for and install plug-in management in this.