How to have the pipeline checked out on Jenkins-agent (scripted pipeline) - jenkins

When I specify a new job in Jenkins and configure to checkout the "Pipeline script from SCM", this repo will be checked out on the jenkins-agent (if it is a declarative pipeline).
I do have a Makefile right next to my pipeline-description that's being used from within that pipeline.
Now I migrated that pipeline to a scripted pipeline (instead of a declarative one).
Unfortunately jenkins now only checks out the repository on the Jenkins-master, so that the agent doesn't have the Makefile available any longer.
I tried to play around with the skipDefaultCheckout() function that is mentioned in this answer, but this doesn't help.
I want the repo with my scripted pipeline (and the makefile) to be available on the agent as well. Is there such a possibility?

Related

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.

Loading jenkinsFile from local disk and run the Declarative pipeline on the same Agent

I am setting up a Jenkins locally without SCM.
I have several Pipelines with the same JenkinsFile but with different parameters.
I would like to centralize the JenkinsFile for all the pipelines.
I found a solution originally for a scripted pipeline:
node {
load "/path/to/local/jenkinsFile.groovy"
}
The problem here is that Jenkins needs two agents to run the previous pipeline (one for the loading node, the other to run the pipeline) and both of them won't finish before the end of the pipeline.
Since I have multiples pipelines cron triggered, at some point, all the agents are busy to load the pipeline files, but since there is no more available agent to run each pipeline, the Jenkins process is stuck and then there is a bottleneck in the job queue.
For solutions I imagine:
How can I release the agent after the load of the pipeline?
Is there a way at the first pipeline (load the jenkinsFile) to keep an agent for running the pipeline?

Continuous deployment branch wise using Spinnaker

I'm using Jenkins multibranch pipeline for CI process and for CD using Spinnaker.
I've gone through almost all documents, support channels etc. from spinnaker for "how to create spinnaker multibranch pipeline similarly as jenkins" but didn't find anywhere.
After integrating jenkins to spinnaker, in drop down list of jenkins jobs in spinnaker pipeline configuration, it shows all multibranch jobs separately. Hence for each branch I'd need to go to spinnaker and create pipeline manually.
To solve this, I'm thinking this solution: while running jenkins multibranch pipeline job > create spinnaker pipeline(if not exist) using spin cli with required parameters(branch, version, trigger using jenkins of this running branch job etc) > and trigger the same created spinnaker pipeline after jenkins job executed.
Please advise if there is any other better way to accomplish this.
Thanks.
I am not super familiar with the multibranch plugin, but you can make this simpler by doing [ triggers ] -> [ pipeline stage calling the same pipeline ] rather than calling the entire pipeline via the spin-cli.
Alternatively, if the list of jobs generated is small or well known, you could just update the list of triggers for the same pipeline programmatically as part of your release process.
i.e, in your jenkins job
add this job to list of triggers
run rest of jenkins job
job finishes, spinnaker pipeline triggers

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/

Jenkins pipeline: agent vs node?

What is the difference between an agent and a node in a jenkins pipeline?
I've found those definitions:
Node: A Pipeline performs most of the work in the context of one or more declared node steps.
Agent: The agent directive specifies where the entire Pipeline, or a specific stage, will execute in the Jenkins environment depending on where the agent directive is placed.
So both are used for executing pipeline steps. But when to use which one?
The simple answer is, Agent is for declarative pipelines and node is for scripted pipelines.
In declarative pipelines the agent directive is used for specifying which agent/slave the job/task is to be executed on. This directive only allows you to specify where the task is to be executed, which agent, slave, label or docker image.
On the other hand, in scripted pipelines the node step can be used for executing a script/step on a specific agent, label, slave. The node step optionally takes the agent or label name and then a closure with code that is to be executed on that node.
declarative and scripted pipelines (edit based on the comment):
declarative pipelines is a new extension of the pipeline DSL (it is basically a pipeline script with only one step, a pipeline step with arguments (called directives), these directives should follow a specific syntax. The point of this new format is that it is more strict and therefore should be easier for those new to pipelines, allow for graphical editing and much more.
scripted pipelines is the fallback for advanced requirements.

Resources