Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-52939

Need to lint pipeline from UI, and also parse parameters

      I create a lot of pipelines where I specify the parameters inside the pipeline like this:

       

      pipeline {
          agent any;
          parameters {
              string(defaultValue: 'master',
                     description: 'SCM branch',
                     name: 'BRANCH')
          }
          stages {
              stage("Do stuff") {
                  steps {
                      sh "echo blah"
                  }
              }
          }
      } 

       

      It would be very handy if:

       

      1.  There was a way to invoke the linter for a Pipeline from the classic UI and the blueocean UI.  Right now, this method is a bit clunky to use: https://jenkins.io/doc/book/pipeline/development/#linter

      2.  It would be good if there was an option in the classic UI and blueocean UI to Reload or Update a pipeline.  If this option could lint the pipeline, and update the parameters from the pipeline into the job, that would be very useful.

          [JENKINS-52939] Need to lint pipeline from UI, and also parse parameters

          From IRC discussion:

          https://botbot.me/freenode/jenkins/2018-08-08/?msg=103071157&page=3

          10:31 am rodrigc In the UI for a pipeline, if I had a thing to click on like "Update" or "Reload"
          10:31 am abayer That's very intriguing.
          10:31 am rodrigc which ran the linter, and updated the parameters in the job, that would do mostly what I need
          10:31 am abayer That could maybe work.
          10:31 am Like, that seems legitimately viable.
          10:32 am abayer Hit the button, it'll get the Pipeline script (either from the job config or from SCM), validate it, update job properties (which includes parameters) based on the parsed Pipeline script…it's really plausible. 

          Craig Rodrigues added a comment - From IRC discussion: https://botbot.me/freenode/jenkins/2018-08-08/?msg=103071157&page=3 10:31 am rodrigc In the UI for a pipeline, if I had a thing to click on like "Update" or "Reload" 10:31 am abayer That's very intriguing. 10:31 am rodrigc which ran the linter, and updated the parameters in the job, that would do mostly what I need 10:31 am abayer That could maybe work. 10:31 am Like, that seems legitimately viable. 10:32 am abayer Hit the button, it'll get the Pipeline script (either from the job config or from SCM), validate it, update job properties (which includes parameters) based on the parsed Pipeline script…it's really plausible.

          A workaround for this problem is shown here: https://dev.to/pencillr/jenkins-pipelines-and-their-dirty-secrets-2

          where you can put the following stage in your pipeline:

           

          stages {
                  stage("parameterizing") {
                      steps {
                          script {
                              if ("${params.Invoke_Parameters}" == "Yes") {
                                  currentBuild.result = 'ABORTED'
                                  error('DRY RUN COMPLETED. JOB PARAMETERIZED.')
                              }
                          }
                      }
                  }
          }

           

          Craig Rodrigues added a comment - A workaround for this problem is shown here: https://dev.to/pencillr/jenkins-pipelines-and-their-dirty-secrets-2 where you can put the following stage in your pipeline:   stages { stage( "parameterizing" ) { steps { script { if ( "${params.Invoke_Parameters}" == "Yes" ) { currentBuild.result = 'ABORTED' error( 'DRY RUN COMPLETED. JOB PARAMETERIZED.' ) } } } } }  

          It would be good to fix the Jenkins and Blue Ocean UI so as to eliminate the need for this workaround.

          Craig Rodrigues added a comment - It would be good to fix the Jenkins and Blue Ocean UI so as to eliminate the need for this workaround.

          Craig Rodrigues added a comment - - edited

          It looks like the Blue Ocean Pipeline Editor has some code which calls the pipeline validation URL:

           

          https://github.com/jenkinsci/blueocean-plugin/blob/1510403599e366d124cce71232cdb3aff5423edd/blueocean-pipeline-editor/src/main/js/services/PipelineValidator.js#L115 

          It would be good if there was a way to call the functions in this code outside of the Pipeline editor.

           

          Craig Rodrigues added a comment - - edited It looks like the Blue Ocean Pipeline Editor has some code which calls the pipeline validation URL:   https://github.com/jenkinsci/blueocean-plugin/blob/1510403599e366d124cce71232cdb3aff5423edd/blueocean-pipeline-editor/src/main/js/services/PipelineValidator.js#L115   It would be good if there was a way to call the functions in this code outside of the Pipeline editor.  

          Keith Zantow added a comment -

          rodrigc yes, I mentioned there is a validation function already. If you load the editor, you can simply copy/paste a declarative pipeline - E.g. go to http://<jenkins-host>/blue/organizations/jenkins/pipeline-editor/ then press Ctrl-S / Cmd-S on windows/osx to get a text area to paste the pipeline into. It doesn't validate every bit of the pipeline, though, but does a good job of linting it:

          Keith Zantow added a comment - rodrigc yes, I mentioned there is a validation function already. If you load the editor, you can simply copy/paste a declarative pipeline - E.g. go to http://<jenkins-host>/blue/organizations/jenkins/pipeline-editor/ then press Ctrl-S / Cmd-S on windows/osx to get a text area to paste the pipeline into. It doesn't validate every bit of the pipeline, though, but does a good job of linting it:

          Keith Zantow added a comment -

          I'd suggest to add a different ticket for Updating Input Parameters. It's currently a limitation of pipeline itself, nothing to do with blue ocean or jenkins ui per se.

          Keith Zantow added a comment - I'd suggest to add a different ticket for Updating Input Parameters . It's currently a limitation of pipeline itself, nothing to do with blue ocean or jenkins ui per se.

          Liam Newman added a comment -

          rodrigc 
          I completely agree with what you are asking for here, but this is at least two independent issues.  Both/All  of the issues are valid and worth fixing, but by mushing them together it makes them less well defined and harder to make progress on. Would you mind if we scope this down to just being able to call the linter from the Web UI? 

          The problem of "reloading" the pipeline and refreshing parameters is related, but is actually a harder problem to solve. 

          Liam Newman added a comment - rodrigc   I completely agree with what you are asking for here, but this is at least two independent issues.  Both/All  of the issues are valid and worth fixing, but by mushing them together it makes them less well defined and harder to make progress on. Would you mind if we scope this down to just being able to call the linter from the Web UI?  The problem of "reloading" the pipeline and refreshing parameters is related, but is actually a harder problem to solve. 

          Craig Rodrigues added a comment - - edited

          When I originally filed this ticket, I thought Blue Ocean was the future direction of Jenkins.

          However, if you can expose a link on the classic UI, where I can just click it and it will run the linter on the
          pipeline in the current job, whether it is a Pipeline from SCM, or just a Pipeline,
          that would be a huge usability improvement. bitwiseman thanks!

          The existing way of invoking the linter is convoluted and confusing!
          I can't be bothered to figure out how to do it, and neither can most users of Pipeline. Make it easier!

          Craig Rodrigues added a comment - - edited When I originally filed this ticket, I thought Blue Ocean was the future direction of Jenkins. However, if you can expose a link on the classic UI, where I can just click it and it will run the linter on the pipeline in the current job, whether it is a Pipeline from SCM, or just a Pipeline, that would be a huge usability improvement. bitwiseman thanks! The existing way of invoking the linter is convoluted and confusing! I can't be bothered to figure out how to do it, and neither can most users of Pipeline. Make it easier!

            Unassigned Unassigned
            rodrigc Craig Rodrigues
            Votes:
            8 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated: