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

No way to merge with target branch for a pull request

    XMLWordPrintable

Details

    Description

      When running with the following Jenkinsfile:

      node {
          checkout scm
          echo "My branch is: ${env.BRANCH_NAME}"
          echo "My target branch is: ${env.CHANGE_TARGET}"
      }
      

      The following is printed out:

      [Pipeline] echo
      My branch is: PR-4
      [Pipeline] echo
      My target branch is: null
      

      I thought CHANGE_TARGET would contain the target branch but apparently I am mistaken? The setup I was thinking of is the following:

      Pull request (from a fork):

      • merge with target branch
      • run test suite

      Pull request get merged into a release branch

      • run test suite
      • build and deploy/publish an artifact

      But it seems to be impossible to declare this in a single folder, I would also be happy to do this in two folders, but that seems impossible as well?

      If there was a way to differentiate between a PR and a regular build AND get the target branch for a PR, I could keep Jenkins config to the bare minimum; the link to a repo and let multibranch / pr discovery do all the rest.

      Am I maybe missing something obvious here or am I trying to do the impossible? I combed through the documentation for the plugin and the available docs and snippet generator for the pipeline scripts but came up empty.

      Attachments

        Issue Links

          Activity

            Nothing is setting env.CHANGE_TARGET, I'm not sure why you think it would be there.

            If there was a way to differentiate between a PR and a regular build

            Only by using env.BRANCH_NAME currently. It always starts with "PR-" for pull requests (and the branch name for regular branches).

            get the target branch for a PR

            No, that's not possible. But building a merge commit (cooked locally) would be a sensible new feature. The merge work would need to be done internally, not scripted in the Jenkinsfile. It would be a configuration option.

            amuniz Antonio Muñiz added a comment - Nothing is setting env.CHANGE_TARGET , I'm not sure why you think it would be there. If there was a way to differentiate between a PR and a regular build Only by using env.BRANCH_NAME currently. It always starts with "PR-" for pull requests (and the branch name for regular branches). get the target branch for a PR No, that's not possible. But building a merge commit (cooked locally) would be a sensible new feature. The merge work would need to be done internally, not scripted in the Jenkinsfile. It would be a configuration option.

            Filed as JENKINS-34931

            amuniz Antonio Muñiz added a comment - Filed as JENKINS-34931
            kevin_smets Kevin Smets added a comment -

            Awesome, thanks for the PR workaround with "PR-". Maybe this could be stored in a parameter or something for usage, or separate it into two folders? Or is this the official way to check it?

            I found the env.CHANGE_TARGET in the snippet generator for a pipeline project, Either way it does not matter if the config would allow a merge.

            I will close this issue then since it's covered by https://issues.jenkins-ci.org/browse/JENKINS-34931, thanks again!

            kevin_smets Kevin Smets added a comment - Awesome, thanks for the PR workaround with "PR-". Maybe this could be stored in a parameter or something for usage, or separate it into two folders? Or is this the official way to check it? I found the env.CHANGE_TARGET in the snippet generator for a pipeline project, Either way it does not matter if the config would allow a merge. I will close this issue then since it's covered by https://issues.jenkins-ci.org/browse/JENKINS-34931 , thanks again!

            People

              amuniz Antonio Muñiz
              kevin_smets Kevin Smets
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: