Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions assign pipe10
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
pipeline {
agent none
options {
timestamps()


}
environment {


name='sushmitha'
}
parameters {
string (defaultValue: 'sushmitha', description: 'Enter the username value', name: 'user_name')
choice (name: 'env', choices: ['dev', 'qa', 'prod'],description: 'choose any one')
booleanParam(defaultValue: true, name: 'my_boolean')
}
triggers {
// Periodically trigger every 12 hours
cron('H H/12 * * *')

// Poll SCM every 15 minutes for changes
pollSCM('H/15 * * * *')
}

stages {
stage('Stage-1') {
agent { label 'java'}
when{
anyOf{
branch 'main'
branch 'dev1'
}
}
steps {
sh 'touch tomcat'
echo "this stage is executing by ${params.user_name}"
echo 'Using Secret Text and Username/Password credentials'


}
}

stage('Stage-2') {
agent { label 'java'}
steps {
sh 'touch master'
echo "executing in ${params.dev}"
echo "my boolean value=${params.my_boolean}"
echo "Executing Stage 2"
// Simulate success; this stage should succeed for Stage 3 to run
}
}
stage('Stage-3') {
agent { label 'Agent-2'}
when {

expression { currentBuild.result == null || currentBuild.result == 'SUCCESS' }
}

steps {
sh 'touch tomcat'
echo "echo "Job ${env.JOB_NAME} is running on ${env.JENKINS_URL} and having build no: ${env.BUILD_ID}"" //global variable directly we can reference them
echo "Name is: ${name}" /top levl variable,we need to define
echo " echo 'Executing Stage 3 on agent3 (only on master or dev branch after Stage 2 success)'"
}
}

stage('Stage-4') {
agent { label 'Agent-2'}
when {
// This stage will run only if Stage 3 was successful
expression { currentBuild.result == null || currentBuild.result == 'SUCCESS' }
steps {
echo "executing stage4"
}
}
}


}
}

6 changes: 6 additions & 0 deletions dev1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This is the file in the dev2 branch
this is the 2nd line to check- addin this in dev1 branch
Checking by ading the new line in the dev2 branch
this is the line in the dev2 branch


1 change: 1 addition & 0 deletions pull.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is for pull request
Empty file added push.txt
Empty file.
110 changes: 110 additions & 0 deletions ques7
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@

pipeline {
agent none
parameters {
string defaultValue: 'Jenkins', name: 'env_var1'
choice choices: ['Dev', 'Test', 'Prod'], name: 'env_var2'
booleanParam defaultValue: true, name: 'env_var3'
}

triggers{
cron '30 * * * *'
pollSCM '30 * * * *'
}

environment {
AWS_ACCESS_KEY=credentials('aws_access_key')
GITHUB_CRED=credentials('github_new')
MY_STRING = "${params.env_var1}"
MY_CHOICE = "${params.env_var2}"
MY_BOOLEAN = "${params.env_var3}"
}
stages {

stage('checkout') {
agent{label 'java'}
when{
anyOf{
branch 'main'
branch 'dev1'
}
}
steps {
git branch: 'main', url: 'https://github.com/Veena-devops/java-example.git'
}
}
stage('Test') {
agent{label 'java'}
steps {

echo 'Running unit test and integration test'
echo "Environment Variable MY_STRING: ${MY_STRING}"
echo "Environment Variable MY_CHOICE: ${MY_CHOICE}"
echo "Environment Variable MY_BOOLEAN: ${MY_BOOLEAN}"
}
}




stage('Build') {
agent {label 'Agent-2'}
when {

expression {
(currentBuild.result == null || currentBuild.result == 'SUCCESS')
}

}

steps {

// Using Global Variables
echo "jobname : '$JOB_NAME'"
echo "build no: '$BUILD_NUMBER'"
echo "job URL: '$BUILD_URL'"
echo "Jenkins URL: '$JENKINS_URL'"
}
}

stage('Push') {
agent{label 'Agent-2'}
when {
expression {
(currentBuild.result == null || currentBuild.result == 'SUCCESS')
}
}
steps {
echo 'Pusing artifact to artifactory'
sh 'echo $AWS_ACCESS_KEY'
sh 'echo USERNAME:PASSWORD:: $GITHUB_CRED'
sh 'echo username: $GITHUB_CRED_USR'
sh 'echo password: $GITHUB_CRED_PSW'
}
}

}


post {

always {

emailext body: '''
jobname : '$JOB_NAME'
build no: '$BUILD_NUMBER'
job URL: '$BUILD_URL'
build status: '$BUILD_STATUS'

''', subject: '$JOB_NAME' , from: 'jenkins@example.com', to: 'vlakkamraju11@gmail.com'

}
}
}