Jenkins pipeline: agent vs node? - jenkins

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.

Related

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

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?

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?

Skip a stage in Jenkins pipeline Globally

I have 200+ Jenkinsfile which we have created in a hurry. We did not know about shared libraries at that time. Now we need to skip one of the stages from all the Jobs. Stage name is common in all the Jenkinsfile.
For eg, lets call that stage FOOSTAGE. Is there a way I can depreciate or skip this stage from all the jobs, without changing jenkinsfile. We cannot afford to edit the files as we are short on time.
We have declarative pipeline and My requirement is very simple. I am thinking of it as a when command defined globally for this particular stage FOOSTAGE.

How to add build server details in Jenkins pipeline?

I am having Jenkins in one server and my build server is different. How to point build server in Jenkins pipeline so that my application will build in build server
Using grade and java.
Do we need to use node('Build 1') inside stage?
Suggest me some sample code please.
In Jenkins, your build server called slave machine or Jenkins nodes, which you need
Firstly add this "buildserver" into Jenkins nodes in advance, then you will get node name (or label them like ubuntu-buildserver), see one jenkins distributed build blog
Secondly in scripted pipeline you specify/reference this name in node
node("ubuntu-buildserver")
If you use declarative pipeline, check syntax#agent part.
It is similar for other global configuration like credentialsId, you need define those parameters in jenkins and refer to use them in your pipeline script.

Jenkins pipeline using upstream and downstream dependency

I had some jenkins standalone jobs to build, package and deploy. Now I am connecting them and making 'build' job trigger 'package' job , and 'package' job to trigger 'deploy' job and am passing the required parameters between them.I can also see them neatly in pipeline view.
My question is, can this technically be called a pipeline? Or can I call it a pipeline only if I use pipeline plugin and write groovy script?
Thanks
p.s: Please do not devote this question. It is a sincere question for which I am not able to find the right answer. I want to be technically correct.
In Jenkins context, a pipeline is a job that defines a workflow using pipeline DSL (here, based on Groovy). A pipeline aims to define a bunch of steps (e.g. build + package + deploy in your case) in a single place, allows to define a complex workflow (e.g. parallel steps, input step, try/catch instructions) that can be both replayed and versionned (because it can be saved to git). For more information you should read Jenkins official pipeline documentation that explains in details what a pipeline is.
The kind of jobs you are currently using are called freestyle jobs, and even if they do define a "flow" (by chaining jobs together), they cannot be called pipelines jobs.
In short, pipelines are jobs that use pipeline plugin and groovy script syntax to define the whole application lifecycle, and standard Jenkins 1.x jobs are called freestyle jobs.

Resources