diff --git a/assign pipe10 b/assign pipe10 new file mode 100644 index 0000000..5c0dbf0 --- /dev/null +++ b/assign pipe10 @@ -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" + } + } + } + + + } +} + diff --git a/dev1.txt b/dev1.txt new file mode 100644 index 0000000..647ac9b --- /dev/null +++ b/dev1.txt @@ -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 + + diff --git a/pull.txt b/pull.txt new file mode 100644 index 0000000..9b646a9 --- /dev/null +++ b/pull.txt @@ -0,0 +1 @@ +This file is for pull request diff --git a/push.txt b/push.txt new file mode 100644 index 0000000..e69de29 diff --git a/ques7 b/ques7 new file mode 100644 index 0000000..496214d --- /dev/null +++ b/ques7 @@ -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' + + } + } + } + + + + + + +