Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-64134

Job SDL enable programmatically "Advanced clone behaviours"

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Component/s: job-dsl-plugin
    • Labels:
    • Environment:
    • Similar Issues:

      Description

      Hi,

      My pipelines are managed with multi branch. I source code from GitHub with the GitHub plugin. Every component use Git tags to compute by themselves their version number. By default, Jenkins doesn't fetch tags during clones. So I need to activate "Advanced clone behaviors" (the option "Fetch tags" is enabled by default) for each of my projects.

      My issue is that I didn't found any solution to enable "Advanced clone behaviors" behavior in "multibranchPipelineJob" with CasC plugin. I have searched across, Stack Overflow, web and documentation without ending.

      Here is my example CasC section relative to `jobs` CasC section:

      jobs: - script: |
          multibranchPipelineJob('my-repo') {
            displayName('my-repo')
            description('my-repo')
      
            branchSources {
              github {
                id('my-repo')
                apiUri('https://github.corp.com/api/v3')
                scanCredentialsId('my-creds')
                repoOwner('my-org')
                repository('my-repo')
              }
            }
            orphanedItemStrategy {
              discardOldItems {
                daysToKeep(31)
              }
            }
            triggers {
              // Schedule every minutes
              cron('* * * * *')
            }
            configure {
              // Re-write Git traits
              def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
              // Discover branches
              // See: https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/BranchDiscoveryTrait.java
              traits << 'org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait' {
                // Select only branches (no PRs)
                strategyId(1)
              }
              // Discover tags
              // See: https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/TagDiscoveryTrait.java
              traits << 'org.jenkinsci.plugins.github_branch_source.TagDiscoveryTrait' { }
              // Discover pull-requests
              // See: https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/OriginPullRequestDiscoveryTrait.java
              traits << 'org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait' {
                // Merge automatically PRs with destination
                strategyId(1)
              }
            }
          }
      

      Every time I deploy a new Jenkins instance (this can append multiple times per day with Kubernetes), I have to manually update the option in the GUI for every project I have. This is non-practical and time-consuming.

        Attachments

          Activity

          clementlesne Clément Lesné created issue -
          clementlesne Clément Lesné made changes -
          Field Original Value New Value
          Issue Type New Feature [ 2 ] Improvement [ 4 ]
          clementlesne Clément Lesné made changes -
          Priority Minor [ 4 ] Major [ 3 ]
          clementlesne Clément Lesné made changes -
          Description Hi,

          My pipelines are managed with multi branch. I source code from GitHub with the GitHub plugin. Every component use Git tags to compute by themselves their version number. By default, Jenkins doesn't fetch tags during clones. So I need to activate "Advanced clone behaviors" (the option "Fetch tags" is enabled by default) for each of my projects.

          My issue is that I didn't found any solution to enable "Advanced clone behaviors" behavior in "multibranchPipelineJob" with CasC plugin. I have searched across, Stack Overflow, web and documentation without ending.

          Here is my example CasC section relative to `jobs` CasC section:


          {code:yaml}
          jobs:
          - script: |
              multibranchPipelineJob('my-repo') {
                displayName('my-repo')
                description('my-repo')

                branchSources {
                  github {
                    id('my-repo')
                    apiUri('https://github.corp.com/api/v3&#39;)
                    scanCredentialsId('my-creds')
                    repoOwner('my-org')
                    repository('my-repo')
                  }
                }
                orphanedItemStrategy {
                  discardOldItems {
                    daysToKeep(31)
                  }
                }
                triggers {
                  // Schedule every minutes
                  cron('* * * * *')
                }
                configure {
                  // Re-write Git traits
                  def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
                  // Discover branches
                  // See: https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/BranchDiscoveryTrait.java
                  traits << 'org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait' {
                    // Select only branches (no PRs)
                    strategyId(1)
                  }
                  // Discover tags
                  // See: https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/TagDiscoveryTrait.java
                  traits << 'org.jenkinsci.plugins.github_branch_source.TagDiscoveryTrait' { }
                  // Discover pull-requests
                  // See: https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/OriginPullRequestDiscoveryTrait.java
                  traits << 'org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait' {
                    // Merge automatically PRs with destination
                    strategyId(1)
                  }
                }
              }
          {code}
          Hi,

          My pipelines are managed with multi branch. I source code from GitHub with the GitHub plugin. Every component use Git tags to compute by themselves their version number. By default, Jenkins doesn't fetch tags during clones. So I need to activate "Advanced clone behaviors" (the option "Fetch tags" is enabled by default) for each of my projects.

          My issue is that I didn't found any solution to enable "Advanced clone behaviors" behavior in "multibranchPipelineJob" with CasC plugin. I have searched across, Stack Overflow, web and documentation without ending.

          Here is my example CasC section relative to `jobs` CasC section:
          {code}
          jobs: - script: |
              multibranchPipelineJob('my-repo') {
                displayName('my-repo')
                description('my-repo')

                branchSources {
                  github {
                    id('my-repo')
                    apiUri('https://github.corp.com/api/v3&#39;)
                    scanCredentialsId('my-creds')
                    repoOwner('my-org')
                    repository('my-repo')
                  }
                }
                orphanedItemStrategy {
                  discardOldItems {
                    daysToKeep(31)
                  }
                }
                triggers {
                  // Schedule every minutes
                  cron('* * * * *')
                }
                configure {
                  // Re-write Git traits
                  def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
                  // Discover branches
                  // See: https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/BranchDiscoveryTrait.java
                  traits << 'org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait' {
                    // Select only branches (no PRs)
                    strategyId(1)
                  }
                  // Discover tags
                  // See: https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/TagDiscoveryTrait.java
                  traits << 'org.jenkinsci.plugins.github_branch_source.TagDiscoveryTrait' { }
                  // Discover pull-requests
                  // See: https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/OriginPullRequestDiscoveryTrait.java
                  traits << 'org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait' {
                    // Merge automatically PRs with destination
                    strategyId(1)
                  }
                }
              }
          {code}
          Every times I deploy a new Jenkins instance (this can append multiple times per day with Kubernetes), I have to manually update the option in the GUI for every project I have. This is non-practical and time-consuming.
          clementlesne Clément Lesné made changes -
          Description Hi,

          My pipelines are managed with multi branch. I source code from GitHub with the GitHub plugin. Every component use Git tags to compute by themselves their version number. By default, Jenkins doesn't fetch tags during clones. So I need to activate "Advanced clone behaviors" (the option "Fetch tags" is enabled by default) for each of my projects.

          My issue is that I didn't found any solution to enable "Advanced clone behaviors" behavior in "multibranchPipelineJob" with CasC plugin. I have searched across, Stack Overflow, web and documentation without ending.

          Here is my example CasC section relative to `jobs` CasC section:
          {code}
          jobs: - script: |
              multibranchPipelineJob('my-repo') {
                displayName('my-repo')
                description('my-repo')

                branchSources {
                  github {
                    id('my-repo')
                    apiUri('https://github.corp.com/api/v3&#39;)
                    scanCredentialsId('my-creds')
                    repoOwner('my-org')
                    repository('my-repo')
                  }
                }
                orphanedItemStrategy {
                  discardOldItems {
                    daysToKeep(31)
                  }
                }
                triggers {
                  // Schedule every minutes
                  cron('* * * * *')
                }
                configure {
                  // Re-write Git traits
                  def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
                  // Discover branches
                  // See: https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/BranchDiscoveryTrait.java
                  traits << 'org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait' {
                    // Select only branches (no PRs)
                    strategyId(1)
                  }
                  // Discover tags
                  // See: https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/TagDiscoveryTrait.java
                  traits << 'org.jenkinsci.plugins.github_branch_source.TagDiscoveryTrait' { }
                  // Discover pull-requests
                  // See: https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/OriginPullRequestDiscoveryTrait.java
                  traits << 'org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait' {
                    // Merge automatically PRs with destination
                    strategyId(1)
                  }
                }
              }
          {code}
          Every times I deploy a new Jenkins instance (this can append multiple times per day with Kubernetes), I have to manually update the option in the GUI for every project I have. This is non-practical and time-consuming.
          Hi,

          My pipelines are managed with multi branch. I source code from GitHub with the GitHub plugin. Every component use Git tags to compute by themselves their version number. By default, Jenkins doesn't fetch tags during clones. So I need to activate "Advanced clone behaviors" (the option "Fetch tags" is enabled by default) for each of my projects.

          My issue is that I didn't found any solution to enable "Advanced clone behaviors" behavior in "multibranchPipelineJob" with CasC plugin. I have searched across, Stack Overflow, web and documentation without ending.

          Here is my example CasC section relative to `jobs` CasC section:
          {code:java}
          jobs: - script: |
              multibranchPipelineJob('my-repo') {
                displayName('my-repo')
                description('my-repo')

                branchSources {
                  github {
                    id('my-repo')
                    apiUri('https://github.corp.com/api/v3&#39;)
                    scanCredentialsId('my-creds')
                    repoOwner('my-org')
                    repository('my-repo')
                  }
                }
                orphanedItemStrategy {
                  discardOldItems {
                    daysToKeep(31)
                  }
                }
                triggers {
                  // Schedule every minutes
                  cron('* * * * *')
                }
                configure {
                  // Re-write Git traits
                  def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
                  // Discover branches
                  // See: https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/BranchDiscoveryTrait.java
                  traits << 'org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait' {
                    // Select only branches (no PRs)
                    strategyId(1)
                  }
                  // Discover tags
                  // See: https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/TagDiscoveryTrait.java
                  traits << 'org.jenkinsci.plugins.github_branch_source.TagDiscoveryTrait' { }
                  // Discover pull-requests
                  // See: https://github.com/jenkinsci/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/OriginPullRequestDiscoveryTrait.java
                  traits << 'org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait' {
                    // Merge automatically PRs with destination
                    strategyId(1)
                  }
                }
              }
          {code}
          Every time I deploy a new Jenkins instance (this can append multiple times per day with Kubernetes), I have to manually update the option in the GUI for every project I have. This is non-practical and time-consuming.

            People

            Assignee:
            daspilker Daniel Spilker
            Reporter:
            clementlesne Clément Lesné
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: