-
Bug
-
Resolution: Unresolved
-
Major
-
Jenkins 2.7 / Jenkins 2.72 (tried both)
Git plugin 3.0.0
Pipeline 2.4
Bitbucket Plugin 1.1.5
We use web hooks from Bitbucket to trigger our Pipeline jobs. Our job configuration is set up through Job DSL, where multiple branches are specified per job (https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob-scm-git-branches).
However, only incoming hooks for commits to master triggers a build. Through poking around and debugging the BitBucket Plugin, Workflow Job and GitSCM plugins, it seems that none of the BranchSpecs are deserialized from the GitSCM plugin:
In hudson.plugins.git.GitSCM the following field is empty
private List<BranchSpec> branches;
I can see these branches are included in the pipeline job's config.xml:
<?xml version="1.0" encoding="UTF-8"?> <flow-definition> <actions /> <description /> <keepDependencies>false</keepDependencies> <properties> <EnvInjectJobProperty> <info> <propertiesContent>NAME=some-app GIT_CREDENTIALS_ID=bitbucket-jenkins GIT_URL=git@bitbucket.org:some/repo BUILD_MSI=true BUILD_RELEASE_ASSEMBLY=true TEST_JOBS=some-integration-test</propertiesContent> <loadFilesFromMaster>false</loadFilesFromMaster> </info> <on>true</on> <keepJenkinsSystemVariables>true</keepJenkinsSystemVariables> <keepBuildVariables>true</keepBuildVariables> <overrideBuildParameters>false</overrideBuildParameters> <contributors /> </EnvInjectJobProperty> </properties> <triggers> <com.cloudbees.jenkins.plugins.BitBucketTrigger> <spec /> </com.cloudbees.jenkins.plugins.BitBucketTrigger> </triggers> <logRotator> <daysToKeep>-1</daysToKeep> <numToKeep>10</numToKeep> <artifactDaysToKeep>-1</artifactDaysToKeep> <artifactNumToKeep>-1</artifactNumToKeep> </logRotator> <assignedNode>some-docker-node</assignedNode> <canRoam>false</canRoam> <scm class="hudson.plugins.git.GitSCM"> <userRemoteConfigs> <hudson.plugins.git.UserRemoteConfig> <url>git@bitbucket.org:some/repo.git</url> <credentialsId>bitbucket-jenkins</credentialsId> </hudson.plugins.git.UserRemoteConfig> </userRemoteConfigs> <branches> <hudson.plugins.git.BranchSpec> <name>master</name> </hudson.plugins.git.BranchSpec> <hudson.plugins.git.BranchSpec> <name>trigger-test</name> </hudson.plugins.git.BranchSpec> </branches> <configVersion>2</configVersion> <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations> <gitTool>Default</gitTool> <gitConfigName>jenkins</gitConfigName> <gitConfigEmail>no-reply@example.com</gitConfigEmail> <browser class="hudson.plugins.git.browser.BitbucketWeb"> <url>https://bitbucket.org/some/repo</url> </browser> </scm> <publishers> <jenkins.plugins.hipchat.HipChatNotifier> <token>token</token> <room>room</room> <startNotification>false</startNotification> <notifySuccess>false</notifySuccess> <notifyAborted>true</notifyAborted> <notifyNotBuilt>true</notifyNotBuilt> <notifyUnstable>true</notifyUnstable> <notifyFailure>true</notifyFailure> <notifyBackToNormal>true</notifyBackToNormal> <startJobMessage /> <completeJobMessage /> </jenkins.plugins.hipchat.HipChatNotifier> </publishers> <buildWrappers> <com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper> <user>bitbucket-jenkins</user> </com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper> </buildWrappers> <definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition"> <script>pipeline script goes here</script> <sandbox>false</sandbox> </definition> </flow-definition>
Hooks from master are the only ones triggering a build, as it seems to be the default branch when a BranchSpec is missing.
I've done the exact same debugging with a regular Maven Job and then everything works as expected. 'List<BranchSpec> branches' is populated with the same branches as specified in the config.xml
A workaround I've thought to use is another type of job just for triggering the Pipeline Job with the correct branch as a parameter...