Answers: <p>This is how I did:</p>
  <pre class="lang-java prettyprint-override"><code>gitParameter {
              // The name of the parameter.
              name('SELECTED_BRANCH')
              // The type of the list of parameters: Tag - list of all commit tags in repository - returns Tag Name Branch - list of all branch in repository - returns Branch Name Revision - list of all revision sha1 in repository followed by its author and date - returns Tag SHA1
              type('PT_BRANCH')
              // In my case this is a variable pointing to the gitlab hook variable
              defaultValue('$gitlabAfter')
              // A description that will be shown to the user later.
              description('Select a git the configuration you want to deploy')
              // Name of branch to look in.
              branch('')
              // Regex used to filter displayed branches.
              // Whatever is captured in the group will be the name used as the value of the SELECTED_BRANCH
              branchFilter('origin/(config\\/.*)')
              // This parameter is used to get tag from git.
              tagFilter('*')
              // Select how to sort the downloaded parameters.
              sortMode('NONE')
              // Which value is selected, after loaded parameters.
              selectedValue('NONE')
              // If in the task are defined multiple repositories, this option specifies which the repository is taken into account on getting data.
              useRepository(&quot;&lt;my git url&gt;.*&quot;)
              // When this option is enabled will show a text field.
              quickFilterEnabled(false)
              // Specify the number of items the list will display.
              // listSize(String value)
          }
  
  </code></pre>
  <p>As strange as it seems, some parameters shouldn't really be necessary, but the plugin requires them anyway, so that's why the config is verbose.</p>
  <p>Also, pay attention that this one is <code>gitParameter</code> and not <code>gitParam</code>, yes, both exist, and they take different parameters.</p>
  <p>For more information about the properties you can go here:</p>
  <p><a href="https://plugins.jenkins.io/git-parameter/" rel="nofollow noreferrer">https://plugins.jenkins.io/git-parameter/</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2020-07-29T17:56:12.833Z
Answers: 2020-07-29T17:56:12.833Z
Answers: Renann
Answers: <pre class="lang-java prettyprint-override"><code>    parameters {
          gitParameter {
              name('selected')
              type('BRANCH')
              defaultValue('master')
              description('')
              branch('')
              branchFilter('origin')  
              tagFilter('*')
              sortMode('NONE')
              selectedValue('NONE')
              useRepository(&quot;&quot;)
              quickFilterEnabled(false) 
          }
  </code></pre>
  <p>Using this syntax it’s able to create a configuration inside the Jenkins job, but once I trigger that job , this configuration is getting removed automatically is there any solution to retain the configuration for every builds</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-06-07T16:54:57.047Z
Answers: 2023-06-08T04:26:20.407Z
Answers: 2023-06-08T04:26:20.407Z
Answers: user40671
Body: <p>I want to fill branchFilter automatically on Jenkins using JobDSL plugin and language.</p>
  
  <p>This is the url of Jenkins Job DSL plugin:</p>
  
  <p><a href="https://jenkinsci.github.io/job-dsl-plugin/#path/javaposse.jobdsl.dsl.jobs.FreeStyleJob.parameters-gitParam" rel="nofollow noreferrer">https://jenkinsci.github.io/job-dsl-plugin/#path/javaposse.jobdsl.dsl.jobs.FreeStyleJob.parameters-gitParam</a></p>
  
  <p>I want to select all branches but master. To do that I have written the following lines:</p>
  
  <pre><code>  //This Build is parametrized
    parameters {
        gitParam('branch') { // https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.BuildParametersContext.gitParam
            description('Git Branch')
            type('BRANCH')
            branchFilter("^(?!.*master).*$")
        }
    }
  </code></pre>
  
  <p>But when compiling it I get error that such method is not available. </p>
  
  <blockquote>
    <p>Processing provided DSL script ERROR: (script, line 28) No signature
    of method: javaposse.jobdsl.dsl.helpers.GitParamContext.branchFilter()
    is applicable for argument types: (java.lang.String) values: [*]
    Possible solutions: tagFilter(java.lang.String)</p>
  </blockquote>
  
  <p><a href="https://i.sstatic.net/HFkyK.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/HFkyK.jpg" alt="enter image description here"></a></p>
  
  <p>Is there any workaround to do this automatically on the script or we have to fulfill that field after job has been created?</p>
  
Tags: <jenkins><job-dsl>
Title: jenkins - gitparam jobdsl - branchFilter
UserDisplayName: joudaon
ThreadText: # jenkins - gitparam jobdsl - branchFilter
  
  (Asked by: username_0 on 2018-05-17)
  
  I want to fill branchFilter automatically on Jenkins using JobDSL plugin and language.
  
  This is the url of Jenkins Job DSL plugin:
  
  <https://jenkinsci.github.io/job-dsl-plugin/#path/javaposse.jobdsl.dsl.jobs.FreeStyleJob.parameters-gitParam>
  
  I want to select all branches but master. To do that I have written the following lines:
  
  ```
    //This Build is parametrized
    parameters {
        gitParam('branch') { // https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.BuildParametersContext.gitParam
            description('Git Branch')
            type('BRANCH')
            branchFilter("^(?!.*master).*$")
        }
    }
  
  ```
  
  But when compiling it I get error that such method is not available.
  
  > Processing provided DSL script ERROR: (script, line 28) No signature
  > of method: javaposse.jobdsl.dsl.helpers.GitParamContext.branchFilter()
  > is applicable for argument types: (java.lang.String) values: [\*]
  > Possible solutions: tagFilter(java.lang.String)
  
  [![enter image description here](https://i.sstatic.net/HFkyK.jpg)](https://i.sstatic.net/HFkyK.jpg)
  
  Is there any workaround to do this automatically on the script or we have to fulfill that field after job has been created?
  
  **Tags:** jenkins, job-dsl
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-07-29. Score: 2
  
  This is how I did:
  
  ```java
  gitParameter {
              // The name of the parameter.
              name('SELECTED_BRANCH')
              // The type of the list of parameters: Tag - list of all commit tags in repository - returns Tag Name Branch - list of all branch in repository - returns Branch Name Revision - list of all revision sha1 in repository followed by its author and date - returns Tag SHA1
              type('PT_BRANCH')
              // In my case this is a variable pointing to the gitlab hook variable
              defaultValue('$gitlabAfter')
              // A description that will be shown to the user later.
              description('Select a git the configuration you want to deploy')
              // Name of branch to look in.
              branch('')
              // Regex used to filter displayed branches.
              // Whatever is captured in the group will be the name used as the value of the SELECTED_BRANCH
              branchFilter('origin/(config\\/.*)')
              // This parameter is used to get tag from git.
              tagFilter('*')
              // Select how to sort the downloaded parameters.
              sortMode('NONE')
              // Which value is selected, after loaded parameters.
              selectedValue('NONE')
              // If in the task are defined multiple repositories, this option specifies which the repository is taken into account on getting data.
              useRepository("<my git url>.*")
              // When this option is enabled will show a text field.
              quickFilterEnabled(false)
              // Specify the number of items the list will display.
              // listSize(String value)
          }
  
  ```
  
  As strange as it seems, some parameters shouldn't really be necessary, but the plugin requires them anyway, so that's why the config is verbose.
  
  Also, pay attention that this one is `gitParameter` and not `gitParam`, yes, both exist, and they take different parameters.
  
  For more information about the properties you can go here:
  
  <https://plugins.jenkins.io/git-parameter/>
  
  
  ---
  
  ### Answer by username_2 on 2023-06-07. Score: 0
  
  ```java
      parameters {
          gitParameter {
              name('selected')
              type('BRANCH')
              defaultValue('master')
              description('')
              branch('')
              branchFilter('origin')  
              tagFilter('*')
              sortMode('NONE')
              selectedValue('NONE')
              useRepository("")
              quickFilterEnabled(false) 
          }
  
  ```
  
  Using this syntax it’s able to create a configuration inside the Jenkins job, but once I trigger that job , this configuration is getting removed automatically is there any solution to retain the configuration for every builds
  
  
  ---
  
  