Search code examples
jenkinsjenkins-pipeline

How to force jenkins to reload a jenkinsfile?


My jenkinsfile has several paremeters, every time I make an update in the parameters (e.g. remove or add a new input) and commit the change to my SCM, I do not see the job input screen updated accordingly in jenkins, I have to run an execution, cancel it and then see my updated fields in

properties([
  parameters([
    string(name: 'a',       defaultValue: 'aa',     description: '*', ),
    string(name: 'b',   description: '*', ),
    string(name: 'c',       description: '*', ),
   ])
])

any clues?


Solution

  • One of the ugliest things I've done to get around this is create a Refresh parameter which basically exits the pipeline right away. This way I can run the pipeline just to update the properties.

    pipeline {
        agent any
        parameters {
            booleanParam(name: 'Refresh',
                        defaultValue: false,
                        description: 'Read Jenkinsfile and exit.')
        }
        stages {
            stage('Read Jenkinsfile') {
                when {
                    expression { return parameters.Refresh == true }
                }
                steps {
                    echo("Ended pipeline early.")        
                }
            }
            stage('Run Jenkinsfile') {
                when {
                    expression { return parameters.Refresh == false }
                }
                stage('Build') {
                    // steps
                }
                stage('Test') {
                    // steps
                }
                stage('Deploy') {
                    // steps
                }
            }
        }
    }
    

    There really must be a better way, but I'm yet to find it :(