# Groovy as shared library to add an additional parameter to a jenkins job

**URL:** <https://community.jenkins.io/t/groovy-as-shared-library-to-add-an-additional-parameter-to-a-jenkins-job/4287>\
**Category:** Ask a question\
**Tags:** question\
**Created:** [October 25, 2022, 7:26am UTC](https://community.jenkins.io/t/groovy-as-shared-library-to-add-an-additional-parameter-to-a-jenkins-job/4287 "2022-10-25T07:26:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gentitope](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/gentitope/32/2504_2.png) [@gentitope](https://community.jenkins.io/u/gentitope)\
**Post date:** [October 25, 2022, 7:26am UTC](https://community.jenkins.io/t/groovy-as-shared-library-to-add-an-additional-parameter-to-a-jenkins-job/4287/1 "2022-10-25T07:26:06Z")

</div>

```auto
I have tried this solution but duplicating the parameters at every run.
I want to be able to create booleanParam and gitParameter parameters for different repos in jenkinsfile stages

@NonCPS
def addParam (repo_name, git_branch) {
// Get existing ParameterDefinitions
existing = currentBuild.rawBuild.parent.properties
.findAll { it.value instanceof hudson.model.ParametersDefinitionProperty }
.collectMany { it.value.parameterDefinitions }
// Create new params and merge them with existing ones
jobParams = [
booleanParam(name: "$**{repo_name}", defaultValue: '', description: "Select to deploy ${repo_name}"),
gitParameter(branch: '',
branchFilter: '.*',
defaultValue: 'develop',
description: "${repo_name}** git parameter build",
listSize: '0',
name: "$**{git_branch}",
quickFilterEnabled: true,
selectedValue: 'NONE',
sortMode: 'DESCENDING_SMART',
tagFilter: '*',
type: 'PT_BRANCH_TAG',
useRepository: "${repo_name}**")
] + existing

// Create properties
properties([
parameters(jobParams)
])
}

Can anyone help me?

```

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [October 25, 2022, 4:08pm UTC](https://community.jenkins.io/t/groovy-as-shared-library-to-add-an-additional-parameter-to-a-jenkins-job/4287/2 "2022-10-25T16:08:27Z")

</div>

> [@gentitope](#):
>
> `] + existing`

You are adding your new parameters to the existing list of parameters. It’ll always be an ever growing list.

> [@gentitope](#):
>
> ```auto
> properties([
> parameters(jobParams)
> ])
> }
> 
> ```

This will affect the next job, not this job.

I’ve not used it, but [Active Choices](https://plugins.jenkins.io/uno-choice/) is a common way to have dynamic properties.
