1. What to use Pipelines & Jenkinsfile for?
- A Pipeline is a series of automated executed job steps, is used to automate CICD (build, test, deploy, report)
- A Jenkinsfile is a text file, is used to define a Jenkins Pipeline.
2. How to use Pipelines & Jenkinsfile?
- Create a Pipeline is create a job in Jenkins >> see more: Create a Pipeline
- Jenkinsfile syntax:
timeout(time: 1, unit: 'HOURS') // Sets a timeout limit for the pipeline
retries(2) // Retries the pipeline 2 times in case of failure
buildDiscarder(logRotator(numToKeepStr: '5')) // Keeps the logs of the last 5 builds
}
MY_VARIABLE = "someValue" // Define a simple environment variable
PASSWORD = credentials('my-credential-id') // Safely inject a password from Jenkins credentials
}
steps {
script {
// Your Groovy code here
}
}
}
Explain:
+ pipeline: define main pipeline
+ agent: specifies agent stages will be executed
+ option: to change default behavior of Jenkins pipeline
+ environment: define variables for using by all stages, steps, script in pipeline.
+ stages: define stages of pipeline
+ stage: define a specific stage
+ steps: contents steps to perform work in stage
+ script: to using Groovy code in pipeline
+ post: define actions or steps that are executed at the end of pipeline
+ always: steps are executed after every run of pipeline
+ success: steps are executed only if pipeline completes success
+ failure: steps are executed only if pipeline fails
Reference
- https://www.jenkins.io/doc/book/pipeline/jenkinsfile/
Thank you.
No comments:
Post a Comment