Skip to content
Snippets Groups Projects

Sr localenvsetup

Merged Siva Mirrapalli requested to merge sr-localenvsetup into dev
1 file
+ 99
99
Compare changes
  • Side-by-side
  • Inline
+ 99
99
def agentLabel= 'ubuntu'
def branch= env.BRANCH_NAME
def port= ''
def lastSuccessfulBuildID= 0
def webhookUrl= 'https://paltech0.webhook.office.com/webhookb2/1ce07c79-9b4b-4e81-ab89-253715dccd77@1680abbe-1a01-4cb0-99e9-452fe05bf615/IncomingWebhook/81bb6c54ad3e4274a4e32cbd0d58e4f9/a74c3df4-0c59-455b-8969-c52e309262f8/V2hWINx0Q8UwZZ_4JmasiyDCZZrrqGluyVr1CBKvfQXRw1'
pipeline {
agent {label agentLabel}
stages{
stage('Git Pull') {
steps {
cleanWs()
script{
git branch:env.BRANCH_NAME, credentialsId: 'anusha-ssh', url: 'git@gitlab.pal.tech:siva.mirrapalli/tech-knights-ai-challenge.git'
branch = "${env.BRANCH_NAME.toLowerCase()}"
echo "${branch}"
if (("$branch").matches('dev(.*)')) {
port = '9803'
branch = 'dev'
}
else if (("$branch").matches('qa')) {
port = '9805'
branch = 'qa'
}
else if (("$branch").matches('main')) {
port = '9807'
branch = 'main'
}
echo "${port}"
echo "${branch}"
def build = currentBuild.previousBuild
while (build !=null){
if (build.result == 'SUCCESS') {
lastSuccessfulBuildID = build.id as Integer
break
}
build = build.previousBuild
}
println lastSuccessfulBuildID
}
}
}
stage('Build Image')
{
steps {
script{
sh "docker build -t talent-rover-api-${branch}-b${BUILD_NUMBER} -f ./server/Dockerfile --no-cache ."
}
}
}
stage('Delete Previous Container')
{
steps {
script{
sh "docker container stop \$(docker container ls -q --filter name=talent-rover-api-${branch})||true"
sh "docker container rm -f \$(docker container ps -a -q --filter name=talent-rover-api-${branch})||true"
}
}
}
stage('Run container')
{
steps {
script{
containerID = sh(
script: "docker run -d -p ${port}:80 --network pt-net --name talent-rover-api-${branch} talent-rover-api-${branch}-b${BUILD_NUMBER}",
returnStdout: true
).trim()
echo "Container ID is ==> ${containerID}"
sh "docker update --restart always ${containerID}"
sh "docker rmi \$(docker images -f=reference=talent-rover-api-${branch}-b${lastSuccessfulBuildID} --format \"{{.ID}}\")||true"
}
}
}
}
post {
always {
script {
office365ConnectorSend (
webhookUrl: webhookUrl,
message: "Please find status of pipeline: Status-<strong>${currentBuild.currentResult}</strong><br><strong>Branch: ${env.BRANCH_NAME}</strong><br>Job: ${env.JOB_NAME}<br>Repository URL: https://gitlab.pal.tech/siva.mirrapalli/tech-knights-ai-challenge.git"
)
}
}
}
def agentLabel= 'ubuntu'
def branch= env.BRANCH_NAME
def port= ''
def lastSuccessfulBuildID= 0
def webhookUrl= 'https://paltech0.webhook.office.com/webhookb2/1ce07c79-9b4b-4e81-ab89-253715dccd77@1680abbe-1a01-4cb0-99e9-452fe05bf615/IncomingWebhook/81bb6c54ad3e4274a4e32cbd0d58e4f9/a74c3df4-0c59-455b-8969-c52e309262f8/V2hWINx0Q8UwZZ_4JmasiyDCZZrrqGluyVr1CBKvfQXRw1'
pipeline {
agent {label agentLabel}
stages{
stage('Git Pull') {
steps {
cleanWs()
script{
git branch:env.BRANCH_NAME, credentialsId: 'readonly', url: 'https://gitlab.pal.tech/siva.mirrapalli/tech-knights-ai-challenge.git
branch = "${env.BRANCH_NAME.toLowerCase()}"
echo "${branch}"
if (("$branch").matches('dev(.*)')) {
port = '9803'
branch = 'dev'
}
else if (("$branch").matches('qa')) {
port = '9805'
branch = 'qa'
}
else if (("$branch").matches('main')) {
port = '9807'
branch = 'main'
}
echo "${port}"
echo "${branch}"
def build = currentBuild.previousBuild
while (build !=null){
if (build.result == 'SUCCESS') {
lastSuccessfulBuildID = build.id as Integer
break
}
build = build.previousBuild
}
println lastSuccessfulBuildID
}
}
}
stage('Build Image')
{
steps {
script{
sh "docker build -t talent-rover-api-${branch}-b${BUILD_NUMBER} -f ./server/Dockerfile --no-cache ."
}
}
}
stage('Delete Previous Container')
{
steps {
script{
sh "docker container stop \$(docker container ls -q --filter name=talent-rover-api-${branch})||true"
sh "docker container rm -f \$(docker container ps -a -q --filter name=talent-rover-api-${branch})||true"
}
}
}
stage('Run container')
{
steps {
script{
containerID = sh(
script: "docker run -d -p ${port}:80 --network pt-net --name talent-rover-api-${branch} talent-rover-api-${branch}-b${BUILD_NUMBER}",
returnStdout: true
).trim()
echo "Container ID is ==> ${containerID}"
sh "docker update --restart always ${containerID}"
sh "docker rmi \$(docker images -f=reference=talent-rover-api-${branch}-b${lastSuccessfulBuildID} --format \"{{.ID}}\")||true"
}
}
}
}
post {
always {
script {
office365ConnectorSend (
webhookUrl: webhookUrl,
message: "Please find status of pipeline: Status-<strong>${currentBuild.currentResult}</strong><br><strong>Branch: ${env.BRANCH_NAME}</strong><br>Job: ${env.JOB_NAME}<br>Repository URL: https://gitlab.pal.tech/siva.mirrapalli/tech-knights-ai-challenge.git"
)
}
}
}
}
\ No newline at end of file
Loading