Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build runs on the remote repo with the Jenkinsfile, not on the main repository (BitBucket) #17

Closed
pilisig opened this issue Sep 28, 2020 · 4 comments
Assignees
Labels

Comments

@pilisig
Copy link

pilisig commented Sep 28, 2020

We have a large git repository stored in BitBucket, let's call it main_repo. I created a new repository for a Jenkinsfile, named jenkinsfile_repo. In the jenkinsfile_repo I created a directory named main_repo and put our Jenkinsfile in it. I created a Multibranch Pipline project in Jenkins, according to the documentation here:

https://plugins.jenkins.io/remote-file/

When I save it, then the scan process starts, collects our branches from the main_repo correctly. But if a change triggers a build on one of those branches, the build process looks like this:
-branch change triggers a build
-it checks out the jenkinsfile_repo
-then tries to run the Jenkinsfile on the jenkinsfile_repo/ not on the main_repo/.
Here is the console log:

Branch indexing
Checking out com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCM into C:\jenkins<main_repo branch name>@script to read main_repo/Jenkinsfile
The recommended git tool is: NONE
using credential 27cc7c94-f898-4cf8-ad4a-51e5cdb95c0f
Cloning the remote Git repository
Cloning repository /scm/sw/jenkinsfile_repo.git

git init C:\jenkins<main_repo branch name>@script # timeout=10
Fetching upstream changes from /scm/sw/jenkinsfile_repo.git
git --version # timeout=10
git --version # 'git version 2.27.0.windows.1'
using GIT_ASKPASS to set credentials
git fetch --tags --force --progress -- /scm/sw/jenkinsfile_repo.git +refs/heads/:refs/remotes/jenkinsfile_repo/ # timeout=10
git config remote.jenkinsfile_repo.url /scm/sw/jenkinsfile_repo.git # timeout=10
git config --add remote.jenkinsfile_repo.fetch +refs/heads/:refs/remotes/jenkinsfile_repo/ # timeout=10
Avoid second fetch
Seen branch in repository jenkinsfile_repo/<main_repo branch name>
Seen branch in repository jenkinsfile_repo/master
Seen 2 remote branches
git show-ref --tags -d # timeout=10
Multiple candidate revisions
Checking out Revision 33938ad54089375aa59ea6c9434f4048a3276707 (jenkinsfile_repo/<main_repo branch name>)
git config core.sparsecheckout # timeout=10
git checkout -f 33938ad54089375aa59ea6c9434f4048a3276707 # timeout=10
Commit message: ""
First time build. Skipping changelog.
Posting build status of INPROGRESS to Bitbucket for commit id [33938ad54089375aa59ea6c9434f4048a3276707] and ref 'null'
[Checks API] No suitable checks publisher found.
Posting build status of FAILED to Bitbucket for commit id [33938ad54089375aa59ea6c9434f4048a3276707] and ref 'null'
[Checks API] No suitable checks publisher found.
ERROR: C:\jenkins<main_repo branch name>@script\main_repo\Jenkinsfile not found

To Reproduce
Steps to reproduce the behavior:
Create a new repository named "jenkinsfile_repo" for storing Jenkins files. It is stored in "/jenkinsfile_repo.git"
Create a directory in the "jenkinsfile_repo" for your project. Name it "main_repo"
Create your Jenkins File, named "Jenkinsfile" under "main_repo" directory, and commit/push it to the "jenkinsfile_repo" repository
Open you Jenkins and create a new MultiBranch Pipeline Project, named "main_repo_job"
Add Branch Sources for your project to build. Fill information for "main_repo".
In the "Build Configuration", change "Mode" to "by Remote Jenkins File Plugin".
Define your script path: "main_repo/Jenkinsfile".
Define your SCM for Jenkins file. For example, it will be the repository /jenkinsfile_repo.git .
Click Save.
Now when a branch changes in the main_repo repository, a build will start. After the Jenkinsfile checkout, the build tries to run Jenkinsfile on their own repository (jenkinsfile_repo), not on the main_repo repository. It will fail, of course, because there isn't any source code in the jenkinsfile_repository.

Expected behavior
If a branch changes in the main_repo repository, then check out that branch, then checkout the Jenkinsfile from jenkinsfile_repo repository and start the compile steps for main_repo described in the Jenkinsfile came from jenkinsfile_repo.

Desktop (please complete the following information):

  • Windows 10, Fedora Linux
  • BitBucket server as git source
  • Jenkins version: 2.249.1, Remote Jenkinsfile Provider plugin version: 1.11
@aytuncbeken aytuncbeken self-assigned this Nov 15, 2020
@aytuncbeken
Copy link
Contributor

Hey,
this seems like a bug. I will check

@aytuncbeken
Copy link
Contributor

Hi @pilisig

I tried to reproduce the problem however Jenkins worked as expected. Could you please send the logs of the job if possible ?
What I did is below,

  • Created a repository in BitBucket, called main_repo
  • Put source.txt file in it with some content
  • Created a repository in Bitbucket, called jenkinsfile_repo
  • Put Jenkinsfile, which prints contents of the source.txt, under directory main_repo in repository jenkinsfile_repo
  • Created a multibranch job with Branch Source which is pointed to main_repo
  • Configured Remote Provider Plugin which is pointed to jenkinsfile_repo with script path main_repo/Jenkinsfile
  • Started build for master branch, finished successfully
  • Made a change in main_repo in file source.txt
  • Branch event occurred and job is started. Job finished with success where I could see the contents of the new source.txt file

@aytuncbeken
Copy link
Contributor

Hi @pilisig
Do you have any updates ? If not I am going to close this issue.

@aytuncbeken
Copy link
Contributor

As I couldn't hear from the user, closing this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants