diff --git a/Jenkinsfile b/Jenkinsfile index b478f86..4ace229 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,9 @@ pipeline { REGISTRY = 'git.virtheart.com' REGISTRY_OWNER = 'virtheart' IMAGE_NAME = "${env.JOB_NAME.replaceAll(/[^a-zA-Z0-9.-]/, '-').toLowerCase()}" - IMAGE_TAG = "${env.BUILD_NUMBER}" + IMAGE_TAG = 'latest' + CONTAINER_PORT = '3000' + HOST_PORT = '3010' } stages { @@ -19,12 +21,7 @@ pipeline { steps { script { def imageFullName = "${REGISTRY}/${REGISTRY_OWNER}/${IMAGE_NAME}:${IMAGE_TAG}" - sh """ - set -x - docker version - docker info - docker build -t ${imageFullName} . || { echo "Docker build failed"; exit 1; } - """ + sh "docker build -t ${imageFullName} ." } } } @@ -34,12 +31,10 @@ pipeline { withCredentials([usernamePassword(credentialsId: 'docker-registry-credentials', usernameVariable: 'REGISTRY_USERNAME', passwordVariable: 'REGISTRY_PASSWORD')]) { script { def imageFullName = "${REGISTRY}/${REGISTRY_OWNER}/${IMAGE_NAME}:${IMAGE_TAG}" - sh """ - set -x - echo ${REGISTRY_PASSWORD} | docker login ${REGISTRY} -u ${REGISTRY_USERNAME} --password-stdin - docker push ${imageFullName} - docker rmi ${imageFullName} - """ + sh ''' + set +x + echo $REGISTRY_PASSWORD | docker login $REGISTRY -u $REGISTRY_USERNAME --password-stdin + docker push ''' + imageFullName } } } @@ -50,11 +45,13 @@ pipeline { script { def imageFullName = "${REGISTRY}/${REGISTRY_OWNER}/${IMAGE_NAME}:${IMAGE_TAG}" sh """ - docker stop ${IMAGE_NAME} || true - docker rm ${IMAGE_NAME} || true - docker run -d --name ${IMAGE_NAME} \ + docker stop $IMAGE_NAME || true + docker rm $IMAGE_NAME || true + docker pull $imageFullName + docker run -d --name $IMAGE_NAME \ + -p $HOST_PORT:$CONTAINER_PORT \ --restart unless-stopped \ - ${imageFullName} + $imageFullName """ } }