pipeline {
agent {
docker { image 'node:7-alpine' }
}
stages {
stage('Test') {
steps {
sh 'node --version'
}
}
}
}
In the
previous section
you may have noticed the agent
directive in each of the examples. The
agent
directive tells Jenkins where and how to execute the Pipeline, or
subset thereof. As you might expect, the agent
is required for all Pipelines.
Underneath the hood, there are a few things agent
causes to happen:
There are several ways to define agents for use in Pipeline, for this tour we will only focus on using an ephemeral Docker container.
Pipeline is designed to easily use Docker images and containers to run inside. This allows the Pipeline to define the environment and tools required without having to configure various system tools and dependencies on agents manually. This approach allows you to use practically any tool which can be packaged in a Docker container.
For more agent specification options, consult the syntax reference.
pipeline {
agent {
docker { image 'node:7-alpine' }
}
stages {
stage('Test') {
steps {
sh 'node --version'
}
}
}
}
When the Pipeline executes, Jenkins will automatically start the specified container and execute the defined steps within it:
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] sh
[guided-tour] Running shell script
+ node --version
v7.4.0
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
Mixing and matching different containers, or other agents, allows quite a lot of flexibility when executing a Pipeline, for more configuration options, continue to "Using environment variables."
Please submit your feedback about this page through this quick form.
Alternatively, if you don't wish to complete the quick form, you can simply indicate if you found this page helpful?
See existing feedback here.