-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile_2
30 lines (25 loc) · 1.16 KB
/
Jenkinsfile_2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
pipeline {
agent any
parameters {
choice(name: 'DEPLOY_ENV', choices: ['main', 'dev'], description: 'Target environment to deploy')
string(name: 'IMAGE_TAG', defaultValue: 'v1.0', description: 'Tag of the Docker image to deploy')
}
stages {
stage('Deploy') {
steps {
script {
// Determine the application name and port based on the chosen environment
def appName = "node${params.DEPLOY_ENV}:${params.IMAGE_TAG}"
def appPort = params.DEPLOY_ENV == 'main' ? '3000:3000' : '3001:3000'
echo "Deploying ${appName} to ${params.DEPLOY_ENV} environment on port ${appPort.split(':')[0]}"
// Pull the specified Docker image
// Stop and remove any existing container with the same name
sh "docker stop ${params.DEPLOY_ENV} || true"
sh "docker rm ${params.DEPLOY_ENV} || true"
// Run the new Docker container
sh "docker run -d --name ${params.DEPLOY_ENV} -p ${appPort} ${appName}"
}
}
}
}
}