jenkinsci / jenkinsci/workflow-multibranch-plugin
[JENKINS-62745] Allow adding new JobProperty values instead of replacing
- Dominant language
- Java
- Stars
- 87
- Forks
- 131
- PR merge metrics
- No merged PRs in 30d
Description
I would like to add new job properties to a multibranch pipeline in a pipeline library.
The idea is to simplify building projects with a `buildProject()` step.
As part of this step I would like to set the following properties by default:
properties([
disableConcurrentBuilds(),
disableResume(),
durabilityHint('PERFORMANCE_OPTIMIZED'),
])
However, if I also define properties in the main Jenkinsfile, those are overwritted by the pipeline library step.
I have seen in other issues that this is the intended behaviour of the properties() step.
Would it be possible to add new steps that add/remove properties (e.g. addJobProperties/removeJobProperties)?
I tried adding a addJobProperties() helper, but was not able to convert the result of the pipeline helpers such as disableResume() to a JobProperty. I am not familiar with the internals of the pipeline/jenkins code so maybe there is a easy way to make the prop as JobProperty line work:
@NonCPS
def call(List/*>*/ args) {
hudson.model.Job job = currentBuild.rawBuild.parent;
echo("Properties before:")
job.getAllProperties().eachWithIndex{ JobProperty entry, int i ->
echo("Property ${i}: ${entry.toString()}")
}
echo("Properties before:")
for (/**/ prop in args) {
job.addProperty(prop as JobProperty);
}
echo("Properties after:")
job.getAllProperties().eachWithIndex{ JobProperty entry, int i ->
echo("Property ${i}: ${entry.toString()}")
}
}
---
Originally reported by arichardson, imported from: Allow adding new JobProperty values instead of replacing
Raw content of original issue
I would like to add new job properties to a multibranch pipeline in a pipeline library.
The idea is to simplify building projects with a `buildProject()` step.
As part of this step I would like to set the following properties by default:
properties([
disableConcurrentBuilds(),
disableResume(),
durabilityHint('PERFORMANCE_OPTIMIZED'),
])However, if I also define properties in the main Jenkinsfile, those are overwritted by the pipeline library step.
I have seen in other issues that this is the intended behaviour of the properties() step.
Would it be possible to add new steps that add/remove properties (e.g. addJobProperties/removeJobProperties)?
I tried adding a addJobProperties() helper, but was not able to convert the result of the pipeline helpers such as disableResume() to a JobProperty<?>. I am not familiar with the internals of the pipeline/jenkins code so maybe there is a easy way to make the prop as JobProperty<?> line work:
@NonCPS
def call(List/*<JobProperty<?>>*/ args) {
hudson.model.Job<?, ?> job = currentBuild.rawBuild.parent;
echo("Properties before:")
job.getAllProperties().eachWithIndex{ JobProperty<?> entry, int i ->
echo("Property ${i}: ${entry.toString()}")
}
echo("Properties before:")
for (/*<JobProperty<?>*/ prop in args) {
job.addProperty(prop as JobProperty<?>);
}
echo("Properties after:")
job.getAllProperties().eachWithIndex{ JobProperty<?> entry, int i ->
echo("Property ${i}: ${entry.toString()}")
}
}
- environment:
Jenkins 2.235.1
Contributor guide
Research direction
Start by tracing the properties() step, the pipeline helpers such as disableResume(), and hudson.model.Job.addProperty as shown in the issue. Determine how additive and removal steps should represent JobProperty values and interact with existing properties. Done means a documented, tested design and implementation that adds or removes properties without replacing unrelated Jenkinsfile properties.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100