Scenario-Based CI - CD
Scenario-Based CI - CD
http://52.66.205.33:8080/generic-webhook-trigger/invoke?token=abcd
For same like that we can achieve for the multi branch as well (so
bacically it will build all the branches if push and having jenkins file
in repo)
first install the pulgin called multibranch scan webhook trigger
where you have to take the url and give it in thr github repo settings
http://52.66.205.33:8080/multibranch-webhook-trigger/invoke?token=my-
string-token
pipeline {
agent any
stages {
stage (build A){
steps {
echo "hellow world"
}
}
}
post {
success {
build job: 'B'
}
failure {
build job: 'c'
}
}
}
parameters {
string (name: 'branch', defaultValues: 'main', description: 'buld
the branch')
}
parameters {
choice (name: 'branch', choices: ['main','nonmain'], description:
'buld the branch')
}
pipeline {
agent any
tools {
jdk 'jdk'
maven 'maven3'
}
parameters {
choice (name: 'branch', choices: ['main','nonmain'], description:
'building branch')
}
stages {
stage('Git checkout') {
steps {
git branch: "${params.branch}", url:
'https://github.com/amrithaws/TC_JenkinsDeploy.git'
}
}
stage('mvn Package') {
steps {
sh 'mvn package'
}
}
}
}
----------------------------------------
senario based jenkins implementation
tools {
jdk 'jdk'
maven 'maven3'
}
stages {
stage('Git checkout') {
steps {
git branch: "main", url:
'https://github.com/amrithaws/TC_JenkinsDeploy.git'
}
}
stage('mvn test') {
when {
changeset "test.txt"
}
steps {
sh 'mvn test'
}
}
stage('mvn Package') {
steps {
sh 'mvn package'
}
}
}
}
>> lets say we have all our project files in side the folder called Dir
which is not in root level in this our pipeline would fail
for that under the pipeline syntax check dir syntax here how it looks
pipeline {
agent any
tools {
jdk 'jdk'
maven 'maven3'
}
stages {
stage('Git checkout') {
steps {
git branch: "main", url:
'https://github.com/amrithaws/TC_JenkinsDeploy.git'
}
}
stage('mvn test') {
steps {
dir('Dir/') {
sh 'mvn test'
}
}
}
}
}
pipeline {
agent any
tools {
jdk 'jdk'
maven 'maven3'
}
stages {
stage('Git checkout') {
steps {
git branch: "main", url:
'https://github.com/amrithaws/TC_JenkinsDeploy.git'
}
}
stage('mvn compile') {
steps {
sh 'mvn test'
}
}
stage('testing') {
paralle {
stage (unit) {
steps {
sh 'mvn test'
}
}
stage (integration) {
steps {
sh 'echo inte'
}
}
stage (pen) {
steps {
sh 'echo test'
}
}
}
}
stage (build) {
step {
sh 'mvn package'
}
}
}
}
lets assume we have stages where a particular stage is taking more than
10secs then
we should have conditon to abort the particular stage.
pipeline {
agent any
tools {
jdk 'jdk'
maven 'maven3'
}
stages {
stage('Git checkout') {
steps {
git branch: "main", url:
'https://github.com/amrithaws/TC_JenkinsDeploy.git'
}
}
stage('mvn build') {
steps {
timeout(time: 10, unit: 'SECONDS'){
sh 'mvn build'
}
}
}
}
}