diff --git a/Deploytoprod.sh b/Deploytoprod.sh new file mode 100644 index 00000000..7b9c6b1b --- /dev/null +++ b/Deploytoprod.sh @@ -0,0 +1,2 @@ +#!/bin/bash +echo "hello I'm on prod" \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index 2eedc184..ba99d9f2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,34 +1,42 @@ -node { - def app - - stage('Clone repository') { - - - checkout scm +pipeline { + agent any + parameters { + choice(choices: 'staging\nproduction', description: 'Which environment?', name: 'ENVIRONMENT') } - - stage('Build image') { - - app = docker.build("raj80dockerid/test") + environment { + GIT_TAG = sh(returnStdout: true, script: 'git describe --always').trim() } - - stage('Test image') { - - - app.inside { - sh 'echo "Tests passed"' + stages { + stage("Checkout") { + steps { + checkout scm + } } - } - - stage('Push image') { - - docker.withRegistry('https://registry.hub.docker.com', 'dockerhub') { - app.push("${env.BUILD_NUMBER}") + stage("Test") { + steps { + sh('chmod 777 run_all_tests.sh ') + sh('./run_all_tests.sh') + } } - } - - stage('Trigger ManifestUpdate') { - echo "triggering updatemanifestjob" - build job: 'updatemanifest', parameters: [string(name: 'DOCKERTAG', value: env.BUILD_NUMBER)] + stage("Deploy to Staging") { + when { + buildingTag() + environment name: 'ENVIRONMENT', value: 'staging' + } + steps { + sh('chmod 777 build_and_publish.sh') + sh('./build_and_publish.sh') + } } + stage("Deploy to Production") { + when { + buildingTag() + environment name: 'ENVIRONMENT', value: 'production' + } + steps { + sh('chmod 777 Deploytoprod.sh') + sh('./Deploytoprod.sh') + } } + } +} \ No newline at end of file diff --git a/Jenkinsfile.back b/Jenkinsfile.back new file mode 100644 index 00000000..cdc9a41c --- /dev/null +++ b/Jenkinsfile.back @@ -0,0 +1,34 @@ +node { + def app + + stage('Clone repository') { + + + checkout scm + } + + stage('Build image') { + + app = docker.build("nikita1239/pro11") + } + + stage('Test image') { + + + app.inside { + sh 'echo "Tests passed"' + } + } + + stage('Push image') { + + docker.withRegistry('https://registry.hub.docker.com', 'dockerhub') { + app.push("${env.BUILD_NUMBER}") + } + } + + stage('Trigger ManifestUpdate') { + echo "triggering updatemanifestjob" + build job: 'updatemanifest', parameters: [string(name: 'DOCKERTAG', value: env.BUILD_NUMBER)] + } +} diff --git a/build_and_publish.sh b/build_and_publish.sh new file mode 100644 index 00000000..b4ec717b --- /dev/null +++ b/build_and_publish.sh @@ -0,0 +1,2 @@ +#!/bin/bash +echo "hello from build and push script Deploy to stage" \ No newline at end of file diff --git a/run_all_tests.sh b/run_all_tests.sh new file mode 100644 index 00000000..48b5f337 --- /dev/null +++ b/run_all_tests.sh @@ -0,0 +1,2 @@ +#!/bin/bash +echo "hello I'm testing here" \ No newline at end of file