Pipeline concept
Select Pipeline Project after giving the name.
Pull the code " https://github.com/tkdhanasekar/jenkins-python.git "
Save the project and build now.
Jenkins File
pipeline {
agent any
stages {
stage('version') {
steps {
sh 'python3 --version'
}
}
stage('hello') {
steps {
sh 'python3 hello.py'
sh 'python3 world.py'
}
}
}
}
Python File 1
print('Hello DevOps')
Python File 2
print('Hello World')
Console Output
Pipeline Logs
Let's Try with "https://github.com/Zulaikha12/git-test"
Create Project & Add the Git , START to EXPLORE
Its trying to Check & Gets into ERROR , so this is where we need to provide the FILE NAME.
Lets Change & Execute one by one
Jenkinsfile.txt
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building.. This is the build phase'
}
}
stage('Test') {
steps {
echo 'Testing.. This is the testing phase'
}
}
stage('Deploy') {
steps {
echo 'Deploying.... This is the deployment phase'
}
}
stage('Postdeploy') {
steps {
echo 'Postdeployment phase....'
}
}
}
}
Markdown inside the script & Paste the script rather than calling the file name in GIT
Jenkinsfile1.txt
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'echo "Hello World"'
sh '''
echo "Multiline shell steps works too"
ls -lah
'''
}
}
}
}
From where this "ls -lah" got executed ? [TBD]
Passing SH script
Jenkinsfile2.txt
pipeline {
agent any
stages {
stage('Deploy') {
steps {
retry(3) {
sh './flakey-deploy.sh'
}
timeout(time: 3, unit: 'MINUTES') {
sh './health-check.sh'
}
}
}
}
}
ERROR:
+ ./flakey-deploy.sh
/var/lib/jenkins/workspace/pipeline_Zulaikha12_Jenkinsfile2@tmp/durable-1c6bcb96/script.sh: 1: ./flakey-deploy.sh: not found
Whether we need to keep the script over this location ? [TBD]
Usage of POST in the Pipeline script
Jenkinsfile3.txt
pipeline {
agent any
stages {
stage('Test') {
steps {
echo 'Fail!'; exit 1
}
}
}
post {
always {
echo 'This will always run'
}
success {
echo 'This will run only if successful'
}
failure {
echo 'This will run only if failed'
}
unstable {
echo 'This will run only if the run was marked as unstable'
}
changed {
echo 'This will run only if the state of the Pipeline has changed'
echo 'For example, if the Pipeline was previously failing but is now successful'
}
}
}
Approve or Reject
Jenkinsfile4.txt
pipeline {
agent any
stages {
stage('Input') {
steps {
input('Do you want to proceed?')
}
}
stage('If Proceed is clicked') {
steps {
print('hello')
}
}
}
}
Writing scipt in Panel
script.txt
pipeline{
agent any
stages{
stage("dev"){
echo"This is DEV environment"
}
stage("UAT"){
echo"Testing in UAT"
}
stage("PROD"){
echo"Go-live"
}
}
}
Apply and Save
Important Points to be Remembered
What is SCM ?
In Jenkins, SCM stands for "Source Code Management". This option instructs Jenkins to obtain your Pipeline from Source Control Management (SCM), which will be your locally cloned Git repository.
What is Agent in Pipeline script ?
What is Any in AGENT ?
Its like , Agent can run in any NODE. Node means OS.
Keep this always Enabled " Use Groovy Sandbox?
Reference :
https://github.com/Zulaikha12/git-test
https://github.com/tkdhanasekar/jenkins-python/
https://www.slideshare.net/EdurekaIN/jenkins-pipeline-tutorial-continuous-delivery-pipeline-using-jenkins-devops-training-edureka?from_search=8
https://www.liatrio.com/blog/building-with-docker-using-jenkins-pipelines
https://github.com/tkdhanasekar/jenkins-ruby/
https://github.com/tkdhanasekar/jenkins-php
Top comments (0)