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

Parameters disappear from pipeline job after running the job

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • job-dsl-plugin
    • None
    • Jenkins ver. 2.53,
      Build Pipeline Plugin 1.5.6
      Pipeline

       

       

       

      Steps to reproduce

      1. I have created Pipeline job
      2. During creation I checked up "This project is parameterized" checkbox and added two Choice parameters
      3. I have run the job and it failed
      4. I checked the configuration of the job and parameters are no longer there and "This project is parameterized"  checkbox is no longer checked up.

          [JENKINS-43758] Parameters disappear from pipeline job after running the job

          Maciej Gawinecki created issue -

          Hi,

          I have the same issue. When job finished successfully there is no such issue. After failure all defined parameters are gone.

          I tried to add at the beginning of job import hudson.mode.* - didn't help. I t help only if I define parameters in pipeline code - but I cannot use Active Choice Reactive Parameter there. Here is the pipeline code:

          import hudson.model.*
          import hudson.EnvVars
          
          pipeline {
              tools {
                  nodejs 'Node 8.1.1'
              }
              environment {
                  BUILD_DIR = "/var/www/new/${BUILD_TAG}"
              }
              agent {
                  label NODE
              }    
              stages {
                  stage('Create dir') {
                      steps {
                          sh 'mkdir -p ${BUILD_DIR}'
                      }
                  }
                  stage('Fetch code') {
                      steps{
                          retry(3) {
                              git credentialsId: 'jenkins', url: 'git@......', branch: '${BRANCH}'
                          }
                      }
                  }
                  stage('npm run build') {
                      steps {
                          sh '''
                          npm install
                          npm run build
                          '''
                      }
                  }
              }
              post {
                  always {
                      echo "Deployment of ${JOB_NAME} service finished with next result:"
                  }
                  success {
                      echo ' SUCCESSFULY!'
                  }
                  failure {
                      echo ' with FAILURE!'
                  }
                  unstable {
                      echo 'UNSTABLE'
                  }
                  changed {
                      echo 'Previous build had different state. If you see it, please carefully chack status.'
                  }
              }    
          }
          

          Dmytro Zhernosiekov added a comment - Hi, I have the same issue. When job finished successfully there is no such issue. After failure all defined parameters are gone. I tried to add at the beginning of job import hudson.mode.* - didn't help. I t help only if I define parameters in pipeline code - but I cannot use Active Choice Reactive Parameter there. Here is the pipeline code: import hudson.model.* import hudson.EnvVars pipeline {     tools {         nodejs 'Node 8.1.1'     }     environment {         BUILD_DIR = "/ var /www/ new /${BUILD_TAG}"     }     agent {         label NODE     }         stages {         stage( 'Create dir' ) {             steps {                 sh 'mkdir -p ${BUILD_DIR}'             }         }         stage( 'Fetch code' ) {             steps{                 retry(3) {                     git credentialsId: 'jenkins' , url: 'git@......' , branch: '${BRANCH}'                 }             }         }         stage( 'npm run build' ) {             steps {                 sh '''                 npm install                 npm run build                 '''             }         }     }     post {         always {             echo "Deployment of ${JOB_NAME} service finished with next result:"         }         success {             echo ' SUCCESSFULY!'         }         failure {             echo ' with FAILURE!'         }         unstable {             echo 'UNSTABLE'         }         changed {             echo 'Previous build had different state. If you see it, please carefully chack status.'         }     }     }

          HI,

          Just found that all parameters described in Jenkins job ( not in pipeline) disappear when I use next section in pipeline:

              options {
                  buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '15'))
                  timeout(time: 20, unit: 'MINUTES')
                  timestamps()
              }
          

          Looks like some conflict in logic. I don't mind to have all options and parameters described in pipeline code, but not all pluging supported there.

          Dmytro Zhernosiekov added a comment - HI, Just found that all parameters described in Jenkins job ( not in pipeline) disappear when I use next section in pipeline:     options {         buildDiscarder(logRotator(numToKeepStr: '5' , artifactNumToKeepStr: '15' ))         timeout(time: 20, unit: 'MINUTES' )         timestamps()     } Looks like some conflict in logic. I don't mind to have all options and parameters described in pipeline code, but not all pluging supported there.

          Andrew Bayer added a comment -

          As of current versions of Declarative (1.1.6 or later), job properties (such as parameters) defined in the job config UI will not be nuked by use of options or triggers (and as of workflow-multibranch 2.16, the same thing is the case for the properties step). The first time you run a build with options/triggers/parameters in a Declarative Pipeline or properties in a Scripted Pipeline after upgrading, the job properties configured in the UI will still get wiped out, but every run after that (and any run of a new job or one that didn't already have job properties configured) will keep them.

          Andrew Bayer added a comment - As of current versions of Declarative (1.1.6 or later), job properties (such as parameters) defined in the job config UI will not be nuked by use of options or triggers (and as of workflow-multibranch 2.16, the same thing is the case for the properties step). The first time you run a build with options / triggers / parameters in a Declarative Pipeline or properties in a Scripted Pipeline after upgrading, the job properties configured in the UI will still get wiped out, but every run after that (and any run of a new job or one that didn't already have job properties configured) will keep them.
          Andrew Bayer made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]

          Alexander Komarov added a comment - - edited

          How is this resolved?  

          1. I generate a pipeline job with Job DSL plugin, with parameters.
          2. In the job's pipeline script, I configure the build discarder using properties{} closure.
          3. Job runs.
          4. Parameters are gone.
          5. I regenerate the job (parameters are back).
          6. Job runs
          7. Parameters are gone.

          Is the solution to only configure parameters in the script?  Should the build properties not be shown in the UI then?  Behavior seems to be misleading.

          What makes matters worse is that this doesn't always happen (or doesn't happen to all of my jobs), and I don't know why.

           

          Alexander Komarov added a comment - - edited How is this resolved?   I generate a pipeline job with Job DSL plugin, with parameters. In the job's pipeline script, I configure the build discarder using properties{} closure. Job runs. Parameters are gone. I regenerate the job (parameters are back). Job runs Parameters are gone. Is the solution to only configure parameters in the script?  Should the build properties not be shown in the UI then?  Behavior seems to be misleading. What makes matters worse is that this doesn't always happen (or doesn't happen to all of my jobs), and I don't know why.  

          I'm reopening because this clearly still happens in my installation. I have core and all plugins from May 2018, way later than the previous comment.  I'm not using Declarative.  

          As I mentioned, I don't know exactly under which conditions this occurs  - it's pretty random.

          Alexander Komarov added a comment - I'm reopening because this clearly still happens in my installation. I have core and all plugins from May 2018, way later than the previous comment.  I'm not using Declarative.   As I mentioned, I don't know exactly under which conditions this occurs  - it's pretty random.
          Alexander Komarov made changes -
          Resolution Original: Fixed [ 1 ]
          Status Original: Resolved [ 5 ] New: Reopened [ 4 ]

          Varun Shar added a comment -

          Thanks akom for reopening this.

          In my case when my pipeline job is triggered from upstream job parameters remains intact even if my job fails but when someone trigger the job manually then it loses the parameters.

              displayName "Feature Tests"      parameters {
                  stringParam('tags', "@regression", 'Test tag to run')
                  stringParam('timeout', "10", 'Test timeout in minutes') lo
                  stringParam('environment', "ci", 'environment to run against')
              }
          }

          Varun Shar added a comment - Thanks akom for reopening this. In my case when my pipeline job is triggered from upstream job parameters remains intact even if my job fails but when someone trigger the job manually then it loses the parameters. displayName "Feature Tests" parameters { stringParam('tags', "@regression", 'Test tag to run') stringParam('timeout', "10", 'Test timeout in minutes') lo stringParam('environment', "ci", 'environment to run against') } }

          Alexander Komarov added a comment - - edited

          I was managing to work around this issue by setting all properties I need at once in the properties{} closure (I generate jobs with Job DSL, and would rather have them set there).  This was working fine, until I reached a total blocker: I cannot set the "Trigger builds remotely" token.

          In other words, I generate a job that has the token set, but after running the job the token disappears, and there is no pipeline DSL for setting it.  

          Sorry, correction - even Job DSL plugin no longer handles "Trigger builds remotely" any more in pipelineJobs (seems to only apply to freestyleJob now), so it's not configurable either at generation time or at runtime by any means.  I had to downgrade to Job DSL 1.69 due to this, see JENKINS-52743

          Jenkins: 2.141, Pipeline-API: 2.29

          BTW: I am not using Declarative.

          Alexander Komarov added a comment - - edited I was managing to work around this issue by setting all properties I need at once in the properties{} closure (I generate jobs with Job DSL, and would rather have them set there).  This was working fine, until I reached a  total blocker : I cannot set the "Trigger builds remotely" token. In other words, I generate a job that has the token set, but after running the job the token disappears, and there is no pipeline DSL for setting it.    Sorry, correction - even Job DSL plugin no longer handles "Trigger builds remotely" any more in pipelineJobs (seems to only apply to freestyleJob now), so it's not configurable either at generation time or at runtime by any means.  I had to downgrade to Job DSL 1.69 due to this, see  JENKINS-52743 Jenkins: 2.141, Pipeline-API: 2.29 BTW: I am not using Declarative.

            Unassigned Unassigned
            dzieciou Maciej Gawinecki
            Votes:
            38 Vote for this issue
            Watchers:
            52 Start watching this issue

              Created:
              Updated: