Multibranch pipelines and jobDSL

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Multibranch pipelines and jobDSL

Ivan Fernandez Calvo
Hi,

We are trying to move to jobDSL our job definitions, at this point we have hit an issue that I am not sure we can move forward.
To define the Multibranch Pipeline jobs everithing works fine except the pull request discovery settings,
Because ForkPullRequestDiscoveryTrait and OriginPullRequestDiscoveryTrait uses the same symbol we have to use a workaround to configure branch discovery.
This workaround is to use a `configure` block in the jobDSL definition to set the proper settings.
This workaround works until jobDSL 1.75, after that it not possible to use the configuration block due to a sandbox issue (see https://issues.jenkins.io/browse/JENKINS-63788)
Does anyone found another workaround valid?


this is our current jobDSL definition, noted the `configure` block is commented

multibranchPipelineJob('test-mbp') {
  primaryView('All')
  displayName('Job test-mbp')
  description('Job test-mbp')
  orphanedItemStrategy {
    discardOldItems {
      numToKeep(20)
      daysToKeep(7)
    }
  }
  branchSources {
    branchSource {
      source {
        github {
          id('apm-shared/oblt-test-env/test-bmp') // IMPORTANT: use a constant and unique identifier
          credentialsId('my-id')
          repoOwner('owner')
          repository('my-repo')
          repositoryUrl('https://github.com/owner/repo.git')
          configuredByUrl(true)
          // The behaviours control what is discovered from the GitHub repository.
          traits {
            checkoutOptionTrait {
              extension {
                // Specify a timeout (in minutes) for checkout.
                timeout(15)
              }
            }
            cleanBeforeCheckoutTrait {
              extension {
                // Deletes untracked submodules and any other subdirectories which contain .git directories.
                deleteUntrackedNestedRepositories(true)
              }
            }
            cloneOptionTrait {
              extension {
                // Perform shallow clone, so that git will not download the history of the project, saving time and disk space when you just want to access the latest version of a repository.
                shallow(true)
                // Deselect this to perform a clone without tags, saving time and disk space when you just want to access what is specified by the refspec.
                noTags(false)
                // Specify a folder containing a repository that will be used by Git as a reference during clone operations.
                reference("/var/lib/jenkins//apm-pipeline-library.git")
                // Specify a timeout (in minutes) for clone and fetch operations.
                timeout(15)
                // Set shallow clone depth, so that git will only download recent history of the project, saving time and disk space when you just want to access the latest commits of a repository.
                depth(5)
                // Perform initial clone using the refspec defined for the repository.
                honorRefspec(false)
              }
            }
            // Discovers branches on the repository.
            // https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/BranchDiscoveryTrait.java#L55-L70
            gitHubBranchDiscovery{
              // Determines which branches are discovered.
              strategyId(1)
            }
            // Discovers tags on the repository.
            gitHubTagDiscovery()
            // filers heads
            headRegexFilter {
              // A Java regular expression to restrict the names.
              regex('(master|main|PR-.*|\\d+\\.x)')
            }
            // ignore push
            //ignoreOnPushNotificationTrait()
            // Defines a custom context label to be sent as part of Github Status notifications for this project.
            notificationContextTrait {
              // The text of the context label for Github status notifications.
              contextLabel('my-ci-context')
              // Appends the relevant suffix to the context label based on the build type.
              typeSuffix(true)
            }
            wipeWorkspaceTrait()
          }
        }
        buildStrategies {
          buildChangeRequests {
            // If the change request / pull request is a merge, there are two reasons for a revision change: The origin of the change request may have changed The target of the change request may ha
            ignoreTargetOnlyChanges(false)
            // Some sources can permit change request / pull request from external entities.
            ignoreUntrustedChanges(true)
          }
          // Builds regular branches whenever a change is detected.
          buildRegularBranches()
          // Builds tags (subject to a configurable tag age time window)
          buildTags {
            atLeastDays('-1')
            // The number of days since the tag was created after which it is no longer eligible for automatic building.
            atMostDays('7')
          }
          // Skip initial build on first branch indexing
          skipInitialBuildOnFirstBranchIndexing()
        }
      }
    }
  }

  // this configuration is broken due https://issues.jenkins.io/browse/JENKINS-63788
  // configure {
  //   // workaround for JENKINS-46202 (https://issues.jenkins-ci.org/browse/JENKINS-46202)
  //   // https://issues.jenkins.io/browse/JENKINS-60874
  //   // Discovers pull requests where the origin repository is the same as the target repository.
  //   // https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/OriginPullRequestDiscoveryTrait.java#L57-L72
  //   def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
  //   traits << 'org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait' {
  //     strategyId 1
  //     trust(class: 'org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$TrustPermission')
  //   }
  //   traits << 'org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait' {
  //     strategyId 1
  //   }
  // }

  factory {
    workflowBranchProjectFactory {
      scriptPath('.ci/Jenkinsfile')
    }
  }
}

--
Un Saludo
Iván Fernández Calvo

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAKo5Qrrm0USDedW%3De-tM8eSfuJFzUXt87eTewkD%3DyMg7hFu9Kw%40mail.gmail.com.