Skip to content

Commit

Permalink
Jenkins env
Browse files Browse the repository at this point in the history
  • Loading branch information
Ujstor committed Oct 25, 2023
1 parent 586eb25 commit 44c1953
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ pipeline {
agent any

environment {
GITHUB_USER = 'ujstor'
GITHUB_REPO = 'probit-exchange-api'
DOCKER_HUB_USERNAME = 'ujstor'
DOCKER_REPO_NAME = 'probitapi'
BRANCH = 'master'
VERSION_PART = 'Patch' // Patch, Minor, Major
DOCKER_JENKINS_CERDIDENTALS_ID = 'be9636c4-b828-41af-ad0b-46d4182dfb06'
TAG = ''
}
}

stages {
stage('Checkout Code') {
steps {
git(url: 'https://github.com/Ujstor/probit-exchange-api/', branch: env.BRANCH_NAME)
script {
git(url: "https://github.com/${GITHUB_USER}/${GITHUB_REPO}/", branch: env.BRANCH_NAME)
}
}
}

Expand All @@ -33,11 +39,11 @@ pipeline {

stage('Generate Docker Image Tag') {
when {
expression { env.BRANCH_NAME == 'master' }
expression { env.BRANCH_NAME == env.BRANCH}
}
steps {
script {
TAG = sh(script: "/var/lib/jenkins/scripts/docker_tag.sh $DOCKER_HUB_USERNAME $DOCKER_REPO_NAME $VERSION_PART", returnStdout: true).trim()
TAG = sh(script: "${JENKINS_HOME}/scripts/docker_tag.sh $DOCKER_HUB_USERNAME $DOCKER_REPO_NAME $VERSION_PART", returnStdout: true).trim()

if (TAG) {
echo "Docker image tag generated successfully: $TAG"
Expand All @@ -50,9 +56,23 @@ pipeline {
}
}

stage('Docker Login') {
when {
expression { env.BRANCH_NAME == env.BRANCH }
}
steps {
script {

withCredentials([usernamePassword(credentialsId: env.DOCKER_JENKINS_CERDIDENTALS_ID, passwordVariable: 'DOCKER_PASSWORD', usernameVariable: 'DOCKER_USERNAME')]) {
sh "docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD"
}
}
}
}

stage('Build') {
when {
expression { env.BRANCH_NAME == 'master' }
expression { env.BRANCH_NAME == env.BRANCH }
}
steps {
script {
Expand All @@ -63,7 +83,7 @@ pipeline {

stage('Deploy') {
when {
expression { env.BRANCH_NAME == 'master' }
expression { env.BRANCH_NAME == env.BRANCH }
}
steps {
script {
Expand All @@ -74,7 +94,7 @@ pipeline {

stage('Environment Cleanup') {
when {
expression { env.BRANCH_NAME == 'master' }
expression { env.BRANCH_NAME == env.BRANCH }
}
steps {
script {
Expand Down

0 comments on commit 44c1953

Please sign in to comment.