I have a multibranch pipeline job where I specify a custom location of Jenkinsfile. Is there a way to retrieve the path of this Jenkinsfile from the pipeline?
Here's what I want to achieve: I have a single git repository that consists of multiple projects (monorepo). Each project has its own Jenkins multibranch pipeline build, they only differ in the name and path to Jenkinsfile. These projects build Docker images and I would like to standardize the Docker image naming by following the project path, which is the directory of Jenkinsfile. At the moment I add the name manually in the Jenkinsfile but I think it would be better if I can just retrieve this information from Jenkins.
Related
I have multiple repositories which require a cd pipeline and all the repositories have their own jenkinsfile with same name. I have configured one jenkins pipeline for all the repositories by adding multiple repositories in "pipeline script from SCM" section.
When any of the repository is updated the pipeline triggers but it uses jenkinsfile of the first repository mentioned in the list of repos.
Is their anyway we can change this behaviour and make the Jenkins job run Jenkinsfile from a repository which triggered the build.
This can be done by shared library https://www.jenkins.io/doc/book/pipeline/shared-libraries/
https://www.tutorialworks.com/jenkins-shared-library/
You can define various logic and functions to manage multiple repositories and their variables.
Also, try to make generic script which can behave based on the supplied parameters.
Previously we had a single monolith in GitLab repository and we used to build project in Jenkins using Jenkinsfile.
Now we are migrating it into multiple microservices and all reside in same GitLab repository. Is it possible to create pipelines for this type of setup or do we need to have each microservice in separate repository. If it is possible please point me to appropriate resources.
Each microservice can have its own Jenkinsfile, you have to tell to the Jenkins job the path of the Jenkinsfile if it is not located at the root path.
In your pipeline configuration job choose "Pipeline script from SCM" and set the "Script Path".
To only checkout the microservice you need, you can use in the "SCM" then "Additional Behaviours" the "Check out to a sub-directory" (then if the Jenkinsfile is now at the pseudo root path, you won't need to change the default "Script Path").
Yes it is possible to create pipelines to build/test/deploy from a single repository.
Use Declarative Pipeline in Jenkins.
You can have your microservices separated in different directories in a single repo and can build them all using a single pipeline using the stages & dir() option in Jenkinsfile. We're building close to 15 components from a single pipeline and push it to it's relevant artifactory from the same job. You can build non-dependent microservice components parallely too.
Documentation --> Jenkins Pipeline,Jenkinsfile
If use a multibranch pipeline in Jenkins, I want to have a build for every specific branch that is made inside my code repo. This works like a charm. But I don't want to provide a Jenkinsfile inside my code repo. Instead I want to define a different CI repo which is providing my CI pipeline scripts.
The problem is that the usual config is not containing the scm option like in the normal config.
Normal pipeline config:
Multibranch pipeline config:
Can somebody tell me how to separate the Jenkinsfile from my source code using a multibranch pipeline?
Just in case someone stunmles over the same problem,
there is a Jenkins plug-in which brings remote Jenkinsfiles for mutlibranch pipleines: https://plugins.jenkins.io/remote-file/
I was trying to access Jenkins Stage View pipeline plugin's temporary files/artifacts, couldn't find the exact location.
I have a multibranch pipeline in Jenkins and need to pass the archive from the pipeline to a job it builds. The copy artifact plugin doesnt seem to support multibranch pipelines. It deletes my source project every time I save. Is there another plugin I can use to get the archive to get passed to the job? Or is there something I need to do to get this plugin working with multibranch pipeline?
The copy artifact plugin doesnt seem to support multibranch pipelines.
Copy Artifact does not care about multibranch. From its perspective, a branch project is simply a job that is in some folder. And it does support folders. You just need to use the correct syntax for the source job. Last I remember, it supports either relative (e.g., ../multibranch/master) or absolute (e.g., /organization/repo/master).