How to force jenkins to reload a jenkinsfile?

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 :(


The Jenkinsfile needs to be executed in order to update the job properties, so you need to start a build with the new file.


Unfortunately the answer of TomDotTom was not working for me - I had the same issue and my jenkins required another stages unter 'Run Jenkinsfile' because of the following error:

Unknown stage section "stage". Starting with version 0.5, steps in a stage must be in a ‘steps’ block.

Also I am using params instead of parameters as variable to check the condition (as described in Jenkins Syntax).

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

applied to Jenkins 2.233