jenkinsci/bitbucket-branch-source-plugin

Master is checked out instead of main

DaSchTour opened this issue ยท 8 comments

Jenkins and plugins versions report

Environment
Jenkins: 2.322
OS: Linux - 4.18.0-305.19.1.el8_4.x86_64
---
ace-editor:1.1
analysis-model-api:10.9.2
ant:1.13
antisamy-markup-formatter:2.7
apache-httpcomponents-client-4-api:4.5.13-1.0
authentication-tokens:1.4
bitbucket:214.v2fd4234d0554
bitbucket-oauth:0.12
bootstrap4-api:4.6.0-3
bootstrap5-api:5.1.3-6
bouncycastle-api:2.25
branch-api:2.7.0
build-timeout:1.20
caffeine-api:2.9.2-29.v717aac953ff3
checks-api:1.7.2
cloudbees-bitbucket-branch-source:751.vda_24678a_f781
cloudbees-credentials:3.3
cloudbees-folder:6.708.ve61636eb_65a_5
cobertura:1.17
code-coverage-api:2.0.4
command-launcher:1.6
conditional-buildstep:1.4.1
config-file-provider:3.9.0
credentials:1074.v60e6c29b_b_44b_
credentials-binding:1.27.1
data-tables-api:1.11.4-1
dependencyanalyzer:0.7
display-url-api:2.3.5
docker-build-step:2.8
docker-commons:1.19
docker-java-api:3.1.5.2
docker-plugin:1.2.6
docker-workflow:1.28
durable-task:493.v195aefbb0ff2
ec2-deployment-dashboard:1.0.10
echarts-api:5.3.0-2
email-ext:2.87
external-monitor-job:191.v363d0d1efdf8
font-awesome-api:6.0.0-1
forensics-api:1.8.1
git:4.10.3
git-client:3.11.0
git-server:1.10
google-container-registry-auth:0.3
google-oauth-plugin:1.0.6
handlebars:3.0.8
handy-uri-templates-2-api:2.1.8-1.0
jackson2-api:2.13.1-246.va8a9f3eaf46a
jacoco:3.3.1
javadoc:217.v905b_86277a_2a_
javax-activation-api:1.2.0-2
javax-mail-api:1.6.2-5
jaxb:2.3.0.1
jdk-tool:1.5
jira:3.7
jnr-posix-api:3.1.7-1
jquery:1.12.4-1
jquery-detached:1.2.1
jquery3-api:3.6.0-2
jsch:0.1.55.2
junit:1.55
ldap:2.8
lockable-resources:2.14
m2release:0.16.2
mailer:408.vd726a_1130320
mapdb-api:1.0.9.0
matrix-auth:3.0.1
matrix-project:1.20
maven-plugin:3.17
mercurial:2.16
momentjs:1.1.1
nexus-jenkins-plugin:3.13.20220201-143240.3d657a5
nodejs:1.5.1
oauth-credentials:0.5
pam-auth:1.7
parameterized-trigger:2.43
pipeline-build-step:2.16
pipeline-graph-analysis:188.v3a01e7973f2c
pipeline-input-step:446.vf27b_0b_83500e
pipeline-milestone-step:100.v60a_03cd446e1
pipeline-model-api:2.2064.v5eef7d0982b_e
pipeline-model-definition:2.2064.v5eef7d0982b_e
pipeline-model-extensions:2.2064.v5eef7d0982b_e
pipeline-npm:0.9.2
pipeline-rest-api:2.21
pipeline-stage-step:291.vf0a8a7aeeb50
pipeline-stage-tags-metadata:2.2064.v5eef7d0982b_e
pipeline-stage-view:2.21
plain-credentials:1.8
plugin-util-api:2.14.0
popper-api:1.16.1-2
popper2-api:2.11.2-1
postbuild-task:1.9
prism-api:1.26.0-2
resource-disposer:0.17
run-condition:1.5
scm-api:595.vd5a_df5eb_0e39
script-security:1131.v8b_b_5eda_c328e
snakeyaml-api:1.29.1
sonar:2.14
ssh-credentials:1.19
ssh-slaves:1.33.0
sshd:3.1.0
structs:308.v852b473a2b8c
subversion:2.15.2
timestamper:1.17
token-macro:277.v7c8f82a_d66b_3
trilead-api:1.0.13
warnings-ng:9.11.1
windows-slaves:1.8
workflow-aggregator:2.6
workflow-api:1138.v619fd5201b_2f
workflow-basic-steps:2.24
workflow-cps:2659.v52d3de6044d0
workflow-cps-global-lib:564.ve62a_4eb_b_e039
workflow-durable-task-step:1121.va_65b_d2701486
workflow-job:1167.v8fe861b_09ef9
workflow-multibranch:711.vdfef37cda_816
workflow-scm-step:2.13
workflow-step-api:622.vb_8e7c15b_c95a_
workflow-support:813.vb_d7c3d2984a_0
ws-cleanup:0.40

What Operating System are you using (both controller, and any agents involved in the problem)?

CentOS 8

Reproduction steps

Create a multibranch build with bitbucket and have a main branch instead of master.

Expected Results

Build is working with main branch.

Actual Results

Build fails because instead of main the script tries to checkout master.

Cloning the remote Git repository
Cloning repository git@bitbucket.org:***/frontend.git
 > /usr/bin/git init /var/lib/jenkins/workspace/***_Frontend_main # timeout=10
Fetching upstream changes from git@bitbucket.org:***/frontend.git
 > /usr/bin/git --version # timeout=10
 > git --version # 'git version 2.27.0'
using GIT_ASKPASS to set credentials bitbucket cloud
 > /usr/bin/git fetch --tags --force --progress -- git@bitbucket.org:***/frontend.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > /usr/bin/git config remote.origin.url git@bitbucket.org:***/frontend.git # timeout=10
 > /usr/bin/git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
Avoid second fetch
 > /usr/bin/git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > /usr/bin/git rev-parse origin/master^{commit} # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
[Bitbucket] Notifying commit build result
[Bitbucket] Build result notified
Finished: FAILURE

Anything else?

No response

I am not seeing this issue. Can you please give a bit more details on your config? Is "main" set as the default branch in the repository settings?

@lifeofguenter yes it is configured as the default branch in bitbucket. I'm not sure what kind of details about my configuration you need.

This being a multibranch project, when Jenkins creates a job for the "main" branch, does name that job "main" or "master"?

Does the config.xml file of the branch job refer to "main" or "master"? Below is a sample of what kinds of references there can be.

<?xml version='1.1' encoding='UTF-8'?>
<flow-definition plugin="workflow-job@1145.v7f2433caa07f">
  <actions>
    <org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction plugin="pipeline-model-definition@1.9.3"/>
    <org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction plugin="pipeline-model-definition@1.9.3">
      <jobProperties>
        <string>jenkins.model.BuildDiscarderProperty</string>
      </jobProperties>
      <triggers/>
      <parameters>
        REDACTED
      </parameters>
      <options/>
    </org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction>
  </actions>
  <keepDependencies>false</keepDependencies>
  <properties>
    <org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty plugin="workflow-multibranch@711.vdfef37cda_816">
      <branch plugin="branch-api@2.7.0">
        <sourceId>REDACTED</sourceId>
        <head class="com.cloudbees.jenkins.plugins.bitbucket.BranchSCMHead" plugin="cloudbees-bitbucket-branch-source@757.vddedc5f2589a_">
          <name>master</name> <!-- ๐Ÿ‘ˆ -->
          <repositoryType>GIT</repositoryType>
        </head>
        <scm class="hudson.plugins.git.GitSCM" plugin="git@4.10.3">
          <configVersion>2</configVersion>
          <userRemoteConfigs>
            <hudson.plugins.git.UserRemoteConfig>
              <name>origin</name>
              <refspec>+refs/heads/master:refs/remotes/origin/master</refspec> <!-- ๐Ÿ‘ˆ -->
              <url>REDACTED</url>
              <credentialsId>REDACTED</credentialsId>
            </hudson.plugins.git.UserRemoteConfig>
          </userRemoteConfigs>
          <branches class="singleton-list">
            <hudson.plugins.git.BranchSpec>
              <name>master</name> <!-- ๐Ÿ‘ˆ -->
            </hudson.plugins.git.BranchSpec>
          </branches>
          <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
          <browser class="hudson.plugins.git.browser.BitbucketWeb">
            <url>REDACTED</url>
          </browser>
          <submoduleCfg class="empty-list"/>
          <extensions>
            <hudson.plugins.git.extensions.impl.CloneOption>
              <shallow>false</shallow>
              <noTags>true</noTags>
              <reference>REDACTED</reference>
              <honorRefspec>true</honorRefspec>
            </hudson.plugins.git.extensions.impl.CloneOption>
            <hudson.plugins.git.extensions.impl.GitLFSPull/>
            <hudson.plugins.git.extensions.impl.PruneStaleBranch/>
          </extensions>
        </scm>
        <properties/>
        <actions>
          <com.cloudbees.jenkins.plugins.bitbucket.BitbucketLink plugin="cloudbees-bitbucket-branch-source@757.vddedc5f2589a_">
            <iconClassName>icon-bitbucket-branch</iconClassName>
            <url>REDACTED?sourceBranch=refs%2Fheads%2Fmaster</url> <!-- ๐Ÿ‘ˆ -->
          </com.cloudbees.jenkins.plugins.bitbucket.BitbucketLink>
          <jenkins.scm.api.metadata.ObjectMetadataAction plugin="scm-api@595.vd5a_df5eb_0e39">
            <objectUrl>REDACTED?sourceBranch=refs%2Fheads%2Fmaster</objectUrl> <!-- ๐Ÿ‘ˆ -->
          </jenkins.scm.api.metadata.ObjectMetadataAction>
          <jenkins.scm.api.metadata.PrimaryInstanceMetadataAction plugin="scm-api@595.vd5a_df5eb_0e39"/>
        </actions>
      </branch>
    </org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty>
    <jenkins.model.BuildDiscarderProperty>
      <strategy class="hudson.tasks.LogRotator">
        <daysToKeep>-1</daysToKeep>
        <numToKeep>50</numToKeep>
        <artifactDaysToKeep>-1</artifactDaysToKeep>
        <artifactNumToKeep>1</artifactNumToKeep>
      </strategy>
    </jenkins.model.BuildDiscarderProperty>
    <hudson.model.ParametersDefinitionProperty>
      REDACTED
    </hudson.model.ParametersDefinitionProperty>
  </properties>
  <definition class="org.jenkinsci.plugins.workflow.multibranch.SCMBinder" plugin="workflow-multibranch@711.vdfef37cda_816">
    <scriptPath>Jenkinsfile</scriptPath>
  </definition>
  <triggers/>
  <disabled>false</disabled>
</flow-definition>

@KalleOlaviNiemitalo I don't have a config.xml

I mean in the Jenkins controller, not in the Git repository.

@KalleOlaviNiemitalo so if I understand this right. There is a global Jenkins Configuration which defines the name of the default branch for all builds?

I am not aware of such a global configuration. Each project has a directory in the Jenkins controller, e.g. /opt/jenkins/jobs/my-project/. If it is a multibranch project, then Jenkins should create a job for each branch. The job has its own directory, e.g. /opt/jenkins/jobs/my-project/branches/main/, and Jenkins creates a config.xml file in that directory. I am interested in whether the incorrect branch name "master" is already in the name of the per-job directory and in its config.xml file, or whether the incorrect name comes from somewhere else when it is time to build the job.

Closing this, I don't believe this is a current bug but depends on your configuration. We work with master and main branches simultaneously without any issues.