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

Gitlab-branch-source Merge Request build failed with Templating Engine

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Labels:
      None
    • Environment:
      jenkins: 2.204.1
      gitlab-branch-source: 1.4.3
      job-dsl: 1.76
      templating-engine: 1.5.1
    • Similar Issues:

      Description

      Issue description
      *Use case*: Gitlab-branch-source Organization Folder + [Jenkins Templating Engine](https://github.com/jenkinsci/templating-engine-plugin)

      Let say I have a Merge Request (MR) from branch A to branch B. Both branches have pipeline_config.groovy in root directory. But when the MR triggers Jenkins build, templating engine doesn't obtain pipeline_config.groovy of any branch, it only obtains pipeline_config.groovy in Governance repo

      If the build is triggered by branch commit, then templating engine works fine (obtain pipeline_config.groovy in both source repo and Governance repo)

      Steps to reproduce the issue

      1. Governance's pipeline_config.groovy

      // restrict individual repository Jenkinsfiles
      allow_scm_jenkinsfile = false
      // skip the default JTE checkout and do it explicitly
      skip_default_checkout = truelibraries{
        merge = true
        gitlab
        sonarqube
      }
      

       

       

      2. Source repo's pipeline_config.groovy

      libraries{
        kubernetes {
          podTemplate = "nodeTemplate"
        }
        npm
      }
      

       

      3. Pipeline template (Jenkinsfile in Governance repo)

       

      startPod {
        clone_source()
        build()
        static_code_analysis()
      }
      

       

      4. JCasc job config

       

      jobs:
        - script: >
            organizationFolder('Gitlab Organization Folder') {
              description("Gitlab folder configured with JCasC")
              displayName('Projects')
              // "Projects"
              organizations {
                gitLabSCMNavigator {
                  projectOwner("owner_id")
                  credentialsId("ssh_key")
                  serverName("gitlab-server")
                  // "Traits" ("Behaviours" in the GUI) that are "declarative-compatible"
                  traits {
                    subGroupProjectDiscoveryTrait() // discover projects inside subgroups
                    gitLabBranchDiscovery {
                      strategyId(3) // discover all branches
                    }
                    originMergeRequestDiscoveryTrait {
                      strategyId(1) // discover MRs
                    }
                    gitLabTagDiscovery() // discover tags
                  }
                }
              }
              // "Traits" ("Behaviours" in the GUI) that are NOT "declarative-compatible"
              // For some 'traits, we need to configure this stuff by hand until JobDSL handles it
              // https://issues.jenkins.io/browse/JENKINS-45504
              configure { node ->
                  def traits = node / navigators / 'io.jenkins.plugins.gitlabbranchsource.GitLabSCMNavigator' / traits
                  traits << 'io.jenkins.plugins.gitlabbranchsource.ForkMergeRequestDiscoveryTrait' {
                      strategyId('2')
                      trust(class: 'io.jenkins.plugins.gitlabbranchsource.ForkMergeRequestDiscoveryTrait$TrustPermission')
                  }
                  //traits << 'io.jenkins.plugins.gitlabbranchsource.SSHCheckoutTrait' {
                  //    credentialsId('ssh_key')
                  //}
              }
              // "Project Recognizers"
              projectFactories {
                  templateMultiBranchProjectFactory()
              }
              // "Orphaned Item Strategy"
              orphanedItemStrategy {
                discardOldItems {
                  daysToKeep(-1)
                  numToKeep(-1)
                }
              }
              // "Scan Organization Folder Triggers" : 1 day
              // We need to configure this stuff by hand because JobDSL only allow 'periodic(int min)' for now
              configure { node ->
                node / triggers / 'com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger' {
                  spec('H H * * *')
                  interval(86400000)
                }
              }
            }

       

      5. Trigger Jenkins build by Merge Request creation

       

      What's the expected result?

      • Templating engine obtains and merges pipeline_config.groovy in both source repo and Governance repo

      What's the actual result?

      • Templating engine doesn't obtain pipeline_config.groovy in source repo, it only obtains pipeline_config.groovy in Governance repo.
      • This lead to build fail with error: No such DSL method startPod

        Attachments

          Activity

          Hide
          tritruong Tri Truong added a comment -

          Update code format

          Show
          tritruong Tri Truong added a comment - Update code format
          Hide
          tritruong Tri Truong added a comment -

          I also post an issue on Jenkins Tempating Engine repo:

          https://github.com/jenkinsci/templating-engine-plugin/issues/42

          Show
          tritruong Tri Truong added a comment - I also post an issue on Jenkins Tempating Engine repo: https://github.com/jenkinsci/templating-engine-plugin/issues/42
          Hide
          sterrana Steven Terrana added a comment -

          Hello, I maintain the Templating Engine Plugin (JTE). 

          Some context here:  JTE fetches files from remote SCM's during initialization by leveraging the SCM API 2.0 spec to create an SCMFileSystem.  It seems as if the gitlab-branch-source plugin does not strictly adhere to the SCM API 2.0 spec. 

          Show
          sterrana Steven Terrana added a comment - Hello, I maintain the Templating Engine Plugin (JTE).  Some context here:  JTE fetches files from remote SCM's during initialization by leveraging the SCM API 2.0 spec to create an SCMFileSystem.  It seems as if the gitlab-branch-source plugin does not strictly adhere to the SCM API 2.0 spec. 
          Show
          casz Joseph Petersen (old) added a comment - Released in https://github.com/jenkinsci/gitlab-branch-source-plugin/releases/tag/gitlab-branch-source-1.4.4

            People

            Assignee:
            sterrana Steven Terrana
            Reporter:
            tritruong Tri Truong
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: