[JIRA] (JENKINS-41392) disableConcurrentBuilds should take an optional boolean parameter that defaults to "true"

18 views
Skip to first unread message

bitwiseman@gmail.com (JIRA)

unread,
Jan 24, 2017, 3:19:01 PM1/24/17
to jenkinsc...@googlegroups.com
Liam Newman created an issue
 
Jenkins / Improvement JENKINS-41392
disableConcurrentBuilds should take an optional boolean parameter that defaults to "true"
Issue Type: Improvement Improvement
Assignee: Unassigned
Components: workflow-job-plugin
Created: 2017/Jan/24 8:18 PM
Priority: Minor Minor
Reporter: Liam Newman

Pipeline is now script, that means that one part of the script (or some library) might call disableConcurrentBuilds and a later part of the script might want to reenable concurrent builds.

Right now that is not possible:
https://github.com/jenkinsci/workflow-job-plugin/blob/b7b488057d42a2c4a0f173795dd16bde3b86a3f6/src/main/java/org/jenkinsci/plugins/workflow/job/properties/DisableConcurrentBuildsJobProperty.java

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

jglick@cloudbees.com (JIRA)

unread,
Feb 10, 2017, 11:40:02 AM2/10/17
to jenkinsc...@googlegroups.com
Jesse Glick resolved as Not A Defect
 

If you do not want to disable them, just remove the property.

Change By: Jesse Glick
Status: Open Resolved
Resolution: Not A Defect

lostinberlin2010@gmail.com (JIRA)

unread,
Jul 17, 2018, 5:08:02 AM7/17/18
to jenkinsc...@googlegroups.com
Steve Boardwell commented on Improvement JENKINS-41392
 
Re: disableConcurrentBuilds should take an optional boolean parameter that defaults to "true"

Hi Jesse Glick, sorry for jumping on an old ticket but is there any reason this cannot be done?

I have the following use case:

  • a single Jenkinsfile is being used for multiple jobs
  • each job can have a different configuration (parameter default values, options such as the buildDiscarder, etc)
  • option values can be set using a custom pipeline config step cOption(String optionName) which returns the value for that particular job (e.g. release branches being given a longer build history than topic branches, etc)

At the moment it looks like this:

pipeline {
    agent none
    options {
    skipDefaultCheckout()
    timestamps()
    buildDiscarder(logRotator(
        artifactDaysToKeepStr: cOption('artifactDaysToKeepStr'),
        artifactNumToKeepStr: cOption('artifactDaysToKeepStr'),
        daysToKeepStr: cOption('daysToKeepStr'),
        numToKeepStr: cOption('numToKeepStr')
        )
    )
    disableConcurrentBuilds()
}

I would like to be able to add something like:

    disableConcurrentBuilds(cOption('disableConcurrentBuilds'))

and have the disableConcurrentBuilds value set depending on the job calling it.

I would be happy to make the changes for it. Just wanted to make sure it is okay to do so first.

This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396)

jglick@cloudbees.com (JIRA)

unread,
Jul 19, 2018, 5:30:01 PM7/19/18
to jenkinsc...@googlegroups.com

Steve Boardwell if you want to have a generic Pipeline script used for multiple jobs, I would advise you to use Scripted syntax rather than Declarative.

lostinberlin2010@gmail.com (JIRA)

unread,
Jul 20, 2018, 3:40:02 AM7/20/18
to jenkinsc...@googlegroups.com

Jesse Glick Sorry, I didn't add the context. It is not meant to be a generic Pipeline script to serve multiple and different jobs. The jobs in question are all the same job in principle, doing the same thing, just for a different branch. We could just as well have the Jenkinsfile configured as a Multibranch Pipeline or even Github Organisation job.

A little off topic, but the cOption thing is simply a way to set some defaults (for the buildDiscarder task for example) based on the BRANCH_NAME. This is possible for stages within the pipeline itself using the "when ... expression" but not at the configuration level.

So whilst we can say "if on release_branch then archive these artifacts (else do not)", we can't say "if on release_branch then keep all the build history else only keep the last 30 builds and artifacts of the last 10 builds". It's either have all your branches save all the build history, or accept losing some of your release branches build history.

Following this, it makes sense to allow the disableConcurrentBuilds to accept a boolean in the same way skipDefaultCheckout does. Having an optional boolean would allow this to be configured rather than being static statement.

jglick@cloudbees.com (JIRA)

unread,
Jul 20, 2018, 3:02:02 PM7/20/18
to jenkinsc...@googlegroups.com

Since your need is specific to Declarative (this would be trivial in Scripted), you should rather open an RFE for Declarative to permit parts of options to use a when clause.

lostinberlin2010@gmail.com (JIRA)

unread,
Jul 30, 2018, 10:15:02 AM7/30/18
to jenkinsc...@googlegroups.com

Hi Jesse Glick, sorry for the late reply. I understand that we can do this quite easily with the Scripted syntax, but then one would lose the benefits of the declarative pipeline such as post-conditions, etc.

I can open an RFE but at the same time I can still see the advantage in being able to configure this parameter with a boolean value. Using templating to create jenkins files, for example, where you could just have an IS_CONCURRENT boolean placeholder to replace á la disableConcurrentBuilds($IS_CONCURRENT), rather than have to set IS_CONCURRENT to either disableConcurrentBuilds() or '' and have an empty line in your Jenkinsfile.

Sorry for being a pain . If it is a 'Won't Do' then so be it.

quickz@cisco.com (JIRA)

unread,
Aug 13, 2018, 8:46:02 PM8/13/18
to jenkinsc...@googlegroups.com
Qun Zhou commented on Improvement JENKINS-41392

Is there update for the issue? I really love the concept of declarative pipeline. We have similar situation. There are multiple repositories and branches share the same jenkinsfile, we want disableConcurrentBuilds for development branches but not the master branch, and we don't want too many jenkinsfile which will bring too much maintenance effort. So a boolean parameter will be perfect, and "when...expression" is an acceptable work-round. But now, we have to define different but very similar jenkinsfile to get the function work.

dev@jmini.fr (JIRA)

unread,
Sep 25, 2018, 5:53:01 AM9/25/18
to jenkinsc...@googlegroups.com

Jesse Glick:

this would be trivial in Scripted

Can you please explain here how "enable concurrent builds" can be activate with in a Scripted Pipeline?

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

jglick@cloudbees.com (JIRA)

unread,
Sep 25, 2018, 10:51:32 AM9/25/18
to jenkinsc...@googlegroups.com

You can pass whatever expression you like to a properties step. Please post to the Jenkins users’ list for usage questions.

amirbarkal@sparkbeyond.com (JIRA)

unread,
Mar 9, 2019, 3:57:03 AM3/9/19
to jenkinsc...@googlegroups.com

Joining Op's request, our use case is very similar: Using the same Jenkinsfile for different jobs with declarative syntax.
This can be implemented by either having the options{} block accept a when{} clause, or (preferably) by having all the options support configurable parameters.

IMO this ticket should be reopened with a definition of done like Op's subject.

antogo289@gmail.com (JIRA)

unread,
Aug 26, 2019, 5:23:03 AM8/26/19
to jenkinsc...@googlegroups.com

This issue should be reopened - the issue is not resolved - those who wish to use declarative syntax cannot easily change the build behavior programmatically for build concurrency. This would be a nice (and simple) way to allow us to do that. 

antogo289@gmail.com (JIRA)

unread,
Aug 26, 2019, 5:28:02 AM8/26/19
to jenkinsc...@googlegroups.com
Anthony O'Gorman edited a comment on Improvement JENKINS-41392
This issue should be reopened - the issue is not resolved - those who wish to use declarative syntax cannot easily change the build behavior programmatically for build concurrency. This would be a nice (and simple) way to allow us to do that. Also, it would help to keep directives consistent, skipDefaultCheckout for example uses the same implementation suggested on this ticket:   https://issues.jenkins-ci.org/browse/JENKINS-41391

jglick@cloudbees.com (JIRA)

unread,
Aug 26, 2019, 9:26:02 AM8/26/19
to jenkinsc...@googlegroups.com

ngeorgievskiy@gmail.com (JIRA)

unread,
Nov 5, 2019, 12:05:06 AM11/5/19
to jenkinsc...@googlegroups.com
Nik Geo commented on Improvement JENKINS-41392

Removing of disableConcurrentBuilds() in PR from scripted pipeline didn't affect my develop branch until I went and manually removed it from branch's config.xml

 

node {
 properties(
  [
   disableConcurrentBuilds(),
  ]
 )
 stage('stage 1') {
  sleep(30000)
 }
}

manual changes to config.xml

<?xml version='1.1' encoding='UTF-8'?>
<flow-definition plugin="workfl...@2.34">
  <actions>
    <org.jenkinsci.plugins.workflow.multibranch.JobPropertyTrackerAction plugin="workflow-m...@2.21">
      <jobPropertyDescriptors>
--        <string>org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty</string>
      </jobPropertyDescriptors>
    </org.jenkinsci.plugins.workflow.multibranch.JobPropertyTrackerAction>
  </actions>


   </org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty>
--    <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/>
  </properties>

 

 

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

ngeorgievskiy@gmail.com (JIRA)

unread,
Nov 5, 2019, 12:06:03 AM11/5/19
to jenkinsc...@googlegroups.com
Nik Geo edited a comment on Improvement JENKINS-41392
Removing of disableConcurrentBuilds() in PR from scripted pipeline didn't affect my develop branch until I went and manually removed it from branch's config.xml

 
{code:java}

node {
properties(
  [
   disableConcurrentBuilds(),
  ]
)
stage('stage 1') {
  sleep(30000)
}
}{code}

manual changes to config.xml
{code:java}

<?xml version='1.1' encoding='UTF-8'?>
<flow-definition plugin="workfl...@2.34">
  <actions>
    <org.jenkinsci.plugins.workflow.multibranch.JobPropertyTrackerAction plugin="workflow-m...@2.21">
      <jobPropertyDescriptors>
--        <string>org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty</string>
      </jobPropertyDescriptors>
    </org.jenkinsci.plugins.workflow.multibranch.JobPropertyTrackerAction>
  </actions>

...

   </org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty>
--    <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/>
  </properties>
  <definition class="org.jenkinsci.plugins.workflow.multibranch.SCMBinder" plugin="workflow-m...@2.21">
    <scriptPath>Jenkinsfile</scriptPath>
  </definition>
  <triggers/>
  <disabled>false</disabled>
{code}
 

 
Reply all
Reply to author
Forward
0 new messages