Now that you have Jenkins running and have installed the Workflow plugin, you are ready to create your first pipeline. Create a new workflow by selecting New Item from the Jenkins home page.
First, give your workflow a name (e.g., “hello-world- flow”). Workflows are simple Groovy scripts, so let’s add the obligatory Hello World. Add a workflow to the Workflow script text area: echo 'Hello world' Now save your workflow, ensuring the Use Groovy Sandbox option is checked (more details to follow on this setting).
echo 'Hello world'
Click Build Now to run your workflow.
Editing Your Workflow
Because workflows are simple text scripts, they are easy to edit. As you’ve seen, workflows can be edited directly in the Jenkins UI when configuring your workflow.

Using the Snippet Generator
To make editing your workflows easier, use the Snippet Generator. The Snippet Generator is dynamically populated with the latest Workflow steps. Depending on the plugins installed in your environment, you may see more available steps.

Loading External Workflow Scripts
Because workflows are text assets, they are ideal to store in a source control system. Workflows can be edited in your external IDE then loaded into Jenkins using the Workflow script from SCM option.
Building Your Workflow
Now that you’ve created a workflow, let’s continue to build on it. For a complex flow, you should leverage Jenkins’ job scheduling queue:
node{ sh 'uname' }
The concept of a node should be familiar to Jenkins users: node is a special step that schedules the contained steps to run by adding them to Jenkins’ build queue. Even better, requesting a node leverages Jenkins’ distributed build system. Of course, to select the right kind of node for your build, the node element takes a label expression:
node('unix && 64-bit'){ echo 'Hello world' }
The node step also creates a workspace: a directory specific to this job where you can check out sources, run commands, and do other work. Resource-intensive work in your pipeline should occur on a node. You can also use the ws step to explicitly ask for another workspace on the current slave, without grabbing a new executor slot. Inside its body all commands run in the second workspace.
Checking out Code
Usually, your workflows will retrieve source code from your source control server. Jenkins Workflow has a simple syntax for retrieving source code, leveraging the many existing SCM plugins for Jenkins.
checkout([$class: 'GitSCM', branches: [[name: '*/ master']], userRemoteConfigs: [[url: 'http://github.com/ cloudbees/todo-api.git']]])
If you happen to use a Git-based SCM like GitHub, there’s an even further simplified syntax:
git 'https://github.com/cloudbees/todo-api.git'
Running Your Workflow
Because workflows are built as Jenkins jobs, they can be built like other jobs. You can use the Build Now feature to manually trigger your build on demand or set up triggers to execute your pipeline based on certain events.
Adding Stages And Steps
Stages are usually the topmost element of Workflow syntax. Stages allow you to group your build step into its component parts. By default, multiple builds of the same workflow can run concurrently. The stage element also allows you to control this concurrency:
stage 'build'
node{ ... }
stage name: 'test', concurrency: 3
node{ ... }
stage name: 'deploy', concurrency: 1
node{ ... }
In this example, we have set a limit of three concurrent executions of the test stage and only one execution of the deploy stage. You will likely want to control concurrency to prevent collisions (for example, deployments).
Newer builds are always given priority when entering a throttled stage; older builds will simply exit early if they are preempted.
General Build Steps
Within your stages, you will add build steps. Just like with free-style Jenkins jobs, build steps make up the core logic of your pipeline. Jenkins Workflow supports any compatible Build Step and populates the Snippet Generator with all available Build Steps in your Jenkins environment.
step([$class: 'JavadocArchiver', javadocDir: 'target/ resources/javadoc', keepAll: false])
step([$class: 'Fingerprinter', targets: 'target/api. war'])
Scripting
Jenkins Workflow supports executing shell (*nix) or batch scripts (Windows) just like free-style jobs:
sh 'sleep 10'
bat 'timeout /t 10'
Scripts can integrate with various other tools and frameworks in your environment—more to come on tools in the next section.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}