├── README.md └── parameters ├── Jenkinsfile.ActiveChoiceParameters └── Jenkinsfile.staticParametes /README.md: -------------------------------------------------------------------------------- 1 | # declarative-pipeline-examples 2 | Example declarative pipeline code for project use. 3 | 4 | The full usage of Declarative pipeline parameter is explained in https://devopscube.com/declarative-pipeline-parameters/ 5 | 6 | Please raise issues if you want more functionality to be added to the pipeline script. 7 | -------------------------------------------------------------------------------- /parameters/Jenkinsfile.ActiveChoiceParameters: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent any 3 | stages { 4 | stage('Parameters'){ 5 | steps { 6 | script { 7 | properties([ 8 | parameters([ 9 | [$class: 'ChoiceParameter', 10 | choiceType: 'PT_SINGLE_SELECT', 11 | description: 'Select the Environemnt from the Dropdown List', 12 | filterLength: 1, 13 | filterable: false, 14 | name: 'Env', 15 | script: [ 16 | $class: 'GroovyScript', 17 | fallbackScript: [ 18 | classpath: [], 19 | sandbox: false, 20 | script: 21 | "return['Could not get The environemnts']" 22 | ], 23 | script: [ 24 | classpath: [], 25 | sandbox: false, 26 | script: 27 | "return['dev','stage','prod']" 28 | ] 29 | ] 30 | ], 31 | [$class: 'CascadeChoiceParameter', 32 | choiceType: 'PT_SINGLE_SELECT', 33 | description: 'Select the AMI from the Dropdown List', 34 | name: 'AMI List', 35 | referencedParameters: 'Env', 36 | script: 37 | [$class: 'GroovyScript', 38 | fallbackScript: [ 39 | classpath: [], 40 | sandbox: false, 41 | script: "return['Could not get Environment from Env Param']" 42 | ], 43 | script: [ 44 | classpath: [], 45 | sandbox: false, 46 | script: ''' 47 | if (Env.equals("dev")){ 48 | return["ami-sd2345sd", "ami-asdf245sdf", "ami-asdf3245sd"] 49 | } 50 | else if(Env.equals("stage")){ 51 | return["ami-sd34sdf", "ami-sdf345sdc", "ami-sdf34sdf"] 52 | } 53 | else if(Env.equals("prod")){ 54 | return["ami-sdf34sdf", "ami-sdf34ds", "ami-sdf3sf3"] 55 | } 56 | ''' 57 | ] 58 | ] 59 | ], 60 | [$class: 'DynamicReferenceParameter', 61 | choiceType: 'ET_ORDERED_LIST', 62 | description: 'Select the AMI based on the following information', 63 | name: 'Image Information', 64 | referencedParameters: 'Env', 65 | script: 66 | [$class: 'GroovyScript', 67 | script: 'return["Could not get AMi Information"]', 68 | script: [ 69 | script: ''' 70 | if (Env.equals("dev")){ 71 | return["ami-sd2345sd: AMI with Java", "ami-asdf245sdf: AMI with Python", "ami-asdf3245sd: AMI with Groovy"] 72 | } 73 | else if(Env.equals("stage")){ 74 | return["ami-sd34sdf: AMI with Java", "ami-sdf345sdc: AMI with Python", "ami-sdf34sdf: AMI with Groovy"] 75 | } 76 | else if(Env.equals("prod")){ 77 | return["ami-sdf34sdf: AMI with Java", "ami-sdf34ds: AMI with Python", "ami-sdf3sf3: AMI with Groovy"] 78 | } 79 | ''' 80 | ] 81 | ] 82 | ] 83 | ]) 84 | ]) 85 | } 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /parameters/Jenkinsfile.staticParametes: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent any 3 | stages { 4 | stage('Setup parameters') { 5 | steps { 6 | script { 7 | properties([ 8 | parameters([ 9 | choice( 10 | choices: ['ONE', 'TWO'], 11 | name: 'PARAMETER_01' 12 | ), 13 | booleanParam( 14 | defaultValue: true, 15 | description: '', 16 | name: 'BOOLEAN' 17 | ), 18 | text( 19 | defaultValue: ''' 20 | this is a multi-line 21 | string parameter example 22 | ''', 23 | name: 'MULTI-LINE-STRING' 24 | ), 25 | string( 26 | defaultValue: 'scriptcrunch', 27 | name: 'STRING-PARAMETER', 28 | trim: true 29 | ) 30 | ]) 31 | ]) 32 | } 33 | } 34 | } 35 | } 36 | } 37 | --------------------------------------------------------------------------------