<p>As implied by the links in comments, for better or for worse, this behavior is an unavoidable consequence of how Pipeline is designed.  Pipeline configuration changes in your Jenkinsfile cannot be picked up by Jenkins without executing your Pipeline.  This includes things such as adding parameters.</p>

<p>My personal advice is to ensure that your Pipeline jobs are non-destructive, or in other words, to ensure that the worst thing that could possibly happen by running a job is nothing.  This allows you to pick up configuration changes by just running your job after committing the changes to your Jenkinsfile, and then you can simply abort the job (or let it run to completion if it's a short job) with the confidence that you won't break anything.  Then subsequent runs will have your configuration changes available.</p>

CC BY-SA 4.0
2019-06-30T21:54:11.720Z
2019-06-30T21:54:11.720Z
jayhendren
<p>My workaround looks like this:</p>

<pre class="lang-java prettyprint-override"><code>pipeline {
    parameters {
        booleanParam(name: 'skip_all_steps', defaultValue: false, description: 'When changed parameters in pipeline, just update code from git')
    }
    stages {
        stage('Stage1'){
            when { not { expression { return params.skip_all_steps } } }
            steps {
                …
            }
        }
        stage('Install requirements') {
            when {
                allOf {
                    expression { return params.install_django_requirements }
                    not { expression { return params.skip_all_steps } }
                }
            }
            steps {
                sh 'pip3 install --upgrade --user -r src-django/requirements.txt'
                }
        }
        …
    }
    post {
        success {
            script {
                if (!params.skip_all_steps.toBoolean() &amp;&amp; params.workspace_cleanup.toBoolean()) {
                    cleanWs()
                }
            }

        }
    }
}
</code></pre>

<p>Be careful:</p>

<ul>
<li>parameters in Jenkins UI will be updated only after <strong>successful</strong> build,</li>
<li>maybe it is better idea to use <code>defaultValue: true</code> for <code>skip_all_steps</code> in your particular case (for example, to avoid running any step on first build)</li>
</ul>

CC BY-SA 4.0
2020-05-04T21:24:37.547Z
2020-06-02T20:31:17.573Z
2020-06-02T20:31:17.573Z
Alexey Vazhnov
<p>A few years ago I used a similar approach:</p>

<pre><code> parameters {
        booleanParam(
                name: 'ABORT_JOB', defaultValue: false,
                description:    'Set this to true if you need to "dry-run" this job without doing any real work.\n' +
                        'The Jenkinsfile will be read and new parameters added. It will exit in the first stage.')
</code></pre>

<p>And in the first stage that runs:</p>

<pre><code>stage('Initialise') {
            steps {
                script {
                    if (params.ABORT_JOB) {
                        currentBuild.result = 'ABORTED'
                        error('Stopping early...')
                    }
</code></pre>

<p>I've since started using JobDSL to generate my jobs.  This simplifies the pipeline code and removes the need to code as above.</p>

CC BY-SA 4.0
2020-05-05T10:51:24.523Z
2020-05-05T10:51:24.523Z
Denham Coote
<p>I'm newbie in Jenkins.
I've created pipeine with <a href="https://jenkins.io/doc/book/pipeline/jenkinsfile/#handling-parameters" rel="nofollow noreferrer">parameters in Jenkinsfile</a> in git. It works fine.</p>

<p>Problem is: when I push <strong>new</strong> parameters into <code>Jenkinsfile</code>, then press button "Build with Parameters", there are no new parameters. I will see them only on next build, after step "Declarative: Checkout SCM" will be done.</p>

<p>I know workaround: add parameter to skip all steps. Then I can run build and skip all steps (except "Declarative: Checkout SCM" of course) and afterwards run build with new parameters.</p>

<p>Question: is there are some magic URL or other possibility to update parameters from git before build?</p>

CC BY-SA 4.0
2019-06-27T19:40:15.227Z
Possible duplicate of [How not to break Jenkins Pipeline when adding new parameters (declarative pipeline)](https://devops.stackexchange.com/questions/4293/how-not-to-break-jenkins-pipeline-when-adding-new-parameters-declarative-pipeli)
Argyle
CC BY-SA 4.0
2019-06-27T20:58:10.787Z
@Argyle, I saw it. Problem is similar, but question is different. But now I noticed two good links:
https://stackoverflow.com/questions/46680573/
https://issues.jenkins-ci.org/browse/JENKINS-41929
Alexey Vazhnov
<jenkins-pipeline>
Jenkins pipeline: do "Declarative: Checkout SCM" step only
Alexey Vazhnov
# Jenkins pipeline: do "Declarative: Checkout SCM" step only

(Asked by: username_0 on 2019-06-26)

I'm newbie in Jenkins.
I've created pipeine with [parameters in Jenkinsfile](https://jenkins.io/doc/book/pipeline/jenkinsfile/#handling-parameters) in git. It works fine.

Problem is: when I push **new** parameters into `Jenkinsfile`, then press button "Build with Parameters", there are no new parameters. I will see them only on next build, after step "Declarative: Checkout SCM" will be done.

I know workaround: add parameter to skip all steps. Then I can run build and skip all steps (except "Declarative: Checkout SCM" of course) and afterwards run build with new parameters.

Question: is there are some magic URL or other possibility to update parameters from git before build?

**Tags:** jenkins-pipeline

> **Comments:**
> **username_1**: Possible duplicate of [How not to break Jenkins Pipeline when adding new parameters (declarative pipeline)](https://devops.stackexchange.com/questions/4293/how-not-to-break-jenkins-pipeline-when-adding-new-parameters-declarative-pipeli)  
> **username_0**: @username_1, I saw it. Problem is similar, but question is different. But now I noticed two good links: https://stackoverflow.com/questions/46680573/ https://issues.jenkins-ci.org/browse/JENKINS-41929  

---

## 3 answers

### Answer by username_2 on 2019-06-30. Score: 2

As implied by the links in comments, for better or for worse, this behavior is an unavoidable consequence of how Pipeline is designed. Pipeline configuration changes in your Jenkinsfile cannot be picked up by Jenkins without executing your Pipeline. This includes things such as adding parameters.

My personal advice is to ensure that your Pipeline jobs are non-destructive, or in other words, to ensure that the worst thing that could possibly happen by running a job is nothing. This allows you to pick up configuration changes by just running your job after committing the changes to your Jenkinsfile, and then you can simply abort the job (or let it run to completion if it's a short job) with the confidence that you won't break anything. Then subsequent runs will have your configuration changes available.


---

### Answer by username_0 on 2020-05-04. Score: 0

My workaround looks like this:
pipeline {
    parameters {
        booleanParam(name: 'skip_all_steps', defaultValue: false, description: 'When changed parameters in pipeline, just update code from git')
    }
    stages {
        stage('Stage1'){
            when { not { expression { return params.skip_all_steps } } }
            steps {
                …
            }
        }
        stage('Install requirements') {
            when {
                allOf {
                    expression { return params.install_django_requirements }
                    not { expression { return params.skip_all_steps } }
                }
            }
            steps {
                sh 'pip3 install --upgrade --user -r src-django/requirements.txt'
                }
        }
        …
    }
    post {
        success {
            script {
                if (!params.skip_all_steps.toBoolean() && params.workspace_cleanup.toBoolean()) {
                    cleanWs()
                }
            }

        }
    }
}

Be careful:

parameters in Jenkins UI will be updated only after successful build,
maybe it is better idea to use defaultValue: true for skip_all_steps in your particular case (for example, to avoid running any step on first build)


---

### Answer by username_3 on 2020-05-05. Score: 0

A few years ago I used a similar approach:
 parameters {
        booleanParam(
                name: 'ABORT_JOB', defaultValue: false,
                description:    'Set this to true if you need to "dry-run" this job without doing any real work.\n' +
                        'The Jenkinsfile will be read and new parameters added. It will exit in the first stage.')

And in the first stage that runs:
stage('Initialise') {
            steps {
                script {
                    if (params.ABORT_JOB) {
                        currentBuild.result = 'ABORTED'
                        error('Stopping early...')
                    }

I've since started using JobDSL to generate my jobs.  This simplifies the pipeline code and removes the need to code as above.


---

