"Pipeline script from SCM" option in multibranch pipeline plugin - jenkins

I have a Git repository with code I'd like to build and cant add a Jenkinsfile in its root. Is there a way to store the Jenkinsfile in one repository and have it build code from another repository?
As in pipeline plugin we have option "Pipeline script from SCM" and can choose from any other repo.
As in multibranch we have "Build Configuration" which ask for script path only, i couldnt get how i pass repo URL or this path would be absolute path in local directory? Any link for this would be helpful

Configure your pipeline with the SCM source pointing to the repo with the Jenkinsfile.
In your pipeline definition there, you can check out other code using the checkout or git steps.

Related

Jenkins multi-branch pipeline - scm object of the Jenkinsfile?

In Jenkins pipeline projects, I can reference the repo of the Jenkinsfile using the scm variable, e.g. checkout scm clones the exact repo at the commit that Jenkins uses for the current build.
Now, I am using a multi-branch project that gets the branches (and the corresponding source) from one repo, but the Jenkinsfile from another one. I.e. "Pipeline" is configured as "Pipeline script from SCM".
In that scenario, the scm variable during the build refers to the branch from the multi-branch config, not to the Jenkinsfile. How do I get the SCM object of the Jenkinsfile's repo?

Ho do I restart the jenkins pipeline with an updated JenkinsFile

I have a Jenkins project with a declarative pipeline defined in a JenkinsFile stored in a SCM. I use the "Pipeline script from SCM" option.
Sometimes if something fails I do a quick fix in the jenkins workspace and rerun the pipeline starting at a specific stage. This is working nicely.
There are cases in which I need to update the JenkinsFile and then do a 'restart at stage' with the updated Jenkins file. However, I can't find the JenkinsFile anywhere in the workspace folder. I need to know the location so I can do a quick fix and then restart the pipeline. Where is the JenkinsFile located?
See "Replay" Pipeline Runs with Modifications:
The "Replay" feature allows for quick modifications and execution of an existing Pipeline without changing the Pipeline configuration or creating a new commit.

Jenkins multibranch with Jenkinsfile in different repo

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/

point to Git repository as source for Jenkins Job DSL job?

I have the option of file system or embedded script - how can I point to a Git repo?
I am asking specifically about the Job DSL not Multibranch Pipelines.
Just add a standard SCM step to your job configuration. In that step, check out the needed repository and branch that contains the DSL script.
The "DSL Scripts" argument then has to point to the script that you checked out in that step.
I don't think you can point it to a git repo using the Process Job DSLs build step. Instead if you use Job DSL in a pipeline script as described here you can check out the repo first on to your job workspace and use the DSL script as target in your jobDsl build step

Tell Jenkins I want to build a specific commit in a pipeline project

I have a pipeline project added to Jenkins. I would like to tell Jenkins to build a specific commit in this project by using a REST query.
The project is configured as Jenkinsfile pipeline project. I would like Jenkins to get the Jenkinsfile from this specific commit I've selected, and then the pipeline script would checkout the code and perform the build.
My problem is that I can't force Jenkins to take Jenkinsfile from my selected commit. I can configure it so it'll get Jenkinsfile from master or any other branch, but I don't know how to parametrize the place where I want Jenkins to take Jenkinsfile from.
I.e. when building commit foo, I want Jenkins to checkout the repository I've provided, switch to commit foo and use Jenkinsfile from this commit. Next build job would want to use Jenkins to build commit bar; in such case Jenkins would clone the repo, switch to the bar commit, and start the Jenkinsfile from the bar commit.
Is this action supported by Jenkins?
Duck debugging in action.
My problem was resolved by making sure the "lightweight checkout" in the Git repository settings pane was un-checked. A bug in Jenkins?

Resources