Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 712
NicolasW Avatar asked Jun 07 '17 21:06

NicolasW


People also ask

How do I update Jenkinsfile in Jenkins?

Log in to your GitHub account. Navigate to the forked repository. Once on the repository page, click on the Jenkinsfile . Next, on the resultant page click on the Edit button to edit your Jenkinsfile .

How do I rerun a failed job in Jenkins?

Configuration. Simply install the plugin, and then check the Post-Build action "Retry build after failure" on your project's configuration page. If the build fails, it will be rescheduled to run again after the time you specified. You can choose how many times to retry running the job.


2 Answers

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

like image 150
TomDotTom Avatar answered Oct 01 '22 08:10

TomDotTom


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

like image 38
fty4 Avatar answered Oct 01 '22 08:10

fty4