Jenkins Multibranch pipeline cannot find Jenkinsfile in subfolder - jenkins

I am using a Jenkins Multibranch pipeline -- specifically, an Organization folder, which monitors all my Bitbucket repos and builds a pipeline for any repo containing a Jenkinsfile. For simplicity, I have configured it to look at only 1 of my repos for now.
Here's my problem:
When the Jenkinsfile is located in the root folder of my repo, everything works fine -- Jenkins sees the Jenkinsfile, and creates the pipeline as defined in that Jenkinsfile.
repo
|
|___> Jenkinsfile
As you can see, Jenkins finds it without any issues:
However, I want to move the Jenkinsfile to a subfolder in my repo (giving me the flexibility to have multiple pipelines defined for 1 repo).
When I move it to a subfolder (jenkins/ci-pipeline/Jenkinsfile), even though I explicitly give that relative file path to Jenkins, it can no longer find the Jenkinsfile!!
repo
|
|___> jenkins
|
|___> ci-pipeline
|
|___> Jenkinsfile
As you can see, despite giving the relative file path (jenkins/ci-pipeline/Jenkinsfile) to Jenkins, it claims it can no longer find the Jenkinsfile:
Incidentally, even though the description of that Jenkins field says it is the "relative location", I tried to give it an absolute file path (${WORKSPACE}/jenkins/ci-pipeline/Jenkinsfile) instead to see if that would work:
Unfortunately, that didn't work either -- also, Jenkins didn't expand its WORKSPACE environment variable:
I have also logged into my Jenkins worker node and confirmed that the Jenkinsfile is present in that subfolder, within the Jenkins workspace for my repo.
Can someone please tell me what I'm doing wrong??
This seems very simple, but it just refuses to work and it's driving me nuts!

As suggested by #Unforgettable631, this appears to be caused by the fact that I have an outdated version of the Bitbucket Branch Source Plugin (2.2.9).
As mentioned in https://issues.jenkins-ci.org/browse/JENKINS-49261, that version of the plugin has a bug where it cannot find the Jenkinsfile if it is in a subfolder.

Related

How to edit / define Jenkinsfile text within Jenkins job?

Sometimes it is not possible (yet) to put Jenkinsfile into git repository.
I think it was possible to edit/define Jenkinsfile content just within job,
but with latest Jenkins, I cannot find such support.
Now I see only filename configuration.
OK, just be sure to select usual Pipeline project and not Multibranch pipeline

How to read yaml file from master using Jenkinsfile pipeline script when jenkins job is running on slave machine?

I am building a Shared Library(I'm not a CI engineer) for Jenkins pipeline. As a part of it, we are thinking of giving configurations in yaml file and have Jenkinsfile pipeline script read from the yaml file.
So, we are planning to commit Jenkinsfile and yaml file in one git repository (let's say repo A) and the job is going to run on a slave machine utilising another git repository (let's say repo B). The Jenkinsfile will be executed from master after it clones repo A. The yaml file is also in master workspace. In the slave, repo B will be cloned and a build will take place as defined in the Jenkinsfile. But the question I have is, how do I read yaml file from Jenkinsfile script without having to clone repo A in slave i.e., how I reference a file present in master and not in slave from Jenkinsfile? This question arises because, whatever file I am trying to open is being opened from slave and not from master.
Thanks in advance.
EDIT:
Soemthing I forgot to mention. We actually thought of using stash from master and unstash in slave. But the problem is that we do only the job configurations and the environment is provided to us by some other team which also provides to many other teams. Because of that, master rarely has executors free. So, even when we run the job, it hangs waiting for the master to be free. Is there any other way to load the yaml file when the pipeline script is being loaded in master's memory?
I think the most straightforward way is to use the stash. Stashes are temporary packages that can be created on one node and copied to any other node.
There is some overhead on master for the package creation so stashes are not recommended for really big files, but they are ideally suited for your usecase of transfering a small configuration file.
node('master') {
// Create temporary stash package on master
stash name: 'MyConfiguration', includes: 'SomeFile.yaml'
}
node('MySlave') {
// Copy to and extract the stash package on slave
unstash 'MyConfiguration'
}
This expects 'SomeFile.yaml' to be in the workspace on master and will also extract it to workspace on slave. In case you want a sub directory of WORKSPACE, simply wrap the stash and/or unstash steps in a dir step.

Jenkinsfile not getting updated in jenkins workspace even though Git is updated

I am using Jenkins 2.73.2 with Blue ocean 1.3.1 in the Linux Redhat. I wanted to build maven project located at GitHub repository. I have created a JenkinsFile for a blue ocean pipeline and recently updated it with some changes which were saved successfully on GitHub repository. But when I am running the pipeline again it is still running the old JenkinsFile.
So I checked the workspace of Jenkins and found that the folder for that pipeline was not updated and has old JenkinsFile which is causing this issue. Now I am stuck and don't know where did I go wrong or what I have missed in configuration/settings?
As susmit says in a comment,
This issue got resolved when I used the option available in the jobs where we can clear the workspace before running any jobs.
to avoid this problem you can use the option "Clear Workspace before running job" available in the jobs parameters.

Where is jenkinsfile downloaded when job fetches pipeline script from SCM

I created a Jenkinsfile and pushed it to master branch.
In Jenkins pipeline job, I selected Pipeline Script from SCM and filled all other details.
When I build this job, it runs properly as expected.
Console log says 'Obtained Jenkinsfile from git <repo url>'.
I am using windows. Jenkins has a folder .jenkins in C:\Users\<Username>.
I looked in workspace folder which is empty until Jenkinsfile started downloading the repo.
Where is Jenkins storing the Jenkinsfile it downloaded in the very first step?
The output on the console log should show the directory where the Jenkinsfile was checked out. It is usually named somthing similar to what the workspace is called, but with an #script or something on the end.

Jenkins 2 Pipeline workspaces xxx#script

I am new to Jenkins 2 and pipeline feature, and I am setting up a project to use the Jenkinsfile for pipeline.
I can see there are 3 workspace created:
project-xxxxx
project-xxxxx#script
project-xxxxx#tmp
When I run tox in pipeline, it complains about no tox.ini found, I suspect it's in side folder project-xxxxx which is empty, but the project files are inside project-xxxxx#script
Should I use checkout scm to populate the workspace with project files? Or am I suppose to use the project files in project-xxxxx#script and how do I do it properly?
Can someone please explain to me how those 3 folders work together?
You should not have to worry about the workspace in a pipeline. You start the build, you get a workspace and anything you checkout out or copy into it should be there.
How do you start the pipeline? Inline script, from scm or via a Multi-Branch or similar job type?
How are you getting files into your workspace?

Resources