Devops-day-9: Create a Jenkins Pipeline Project using declarative pipeline syntax to print “Hello World
Tasks
- Create a Jenkins Pipeline named “HelloWorld Example1”
- Go to the Dashboard > Configure > Pipeline > Select Definition as “Pipeline Script” > And enter the following command.
pipeline {
agent any
stages {
stage('Hello') {
steps {
echo 'Hello World'
}
}
}
}
Click on Save and Build the Pipeline.
In the Pipeline Dashboard, you can see the Stage View as well. Our job is successful.
- This is the Console Output. It says SUCCESS. Also, you can observer that the “HELLO WORLD” is printed.
Task 2: Perform the same task which you did in Task 1, but using a Jenkinsfile.
Create a file named Jenkinsfile in your repository. Write down the below contents into the file and commit the changes. Copy the repository link for further usage.
- Now in Jenkins, create a new Pipeline name “HelloWorldExample2”
- Go to Dashboard > Configuration > Pipeline > Select Definition “Pipeline script from SCM” > Select “Git” for SCM > Paste the repository URL which you previously copied and paste in the Repositories Section > Select the branch name where the Jenkinsfile is located > Click on Save
- Now build the pipeline. The stage view appears. Our build is successful.
When we see the Console Output, we can see that Jenkinsfile is being obtained from GitHub. And then the build progressed.
And we have successfully built the Pipeline Project for the “Hello-World” example.
In this blog, I have discussed Jenkins Pipelines, Jenkinsfile, types of Jenkins pipelines, and an example of how to run a Jenkins Pipeline job. If you have any questions or would like to share your experiences, feel free to leave a comment below.