From 4a961fc5e8f9bf6dccda71b93601d906b22bd9e1 Mon Sep 17 00:00:00 2001 From: James Lambie Date: Thu, 28 Jun 2018 10:31:36 +1200 Subject: [PATCH 1/2] feat: auto discover local port --- Jenkinsfile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index bfb880f..5d58581 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,6 +2,11 @@ pipeline { agent any environment { + FREE_PORT = sh ( + script: "curl https://gist.githubusercontent.com/jimlambie/6a2a6a89481e8e5b518d7c84caf7bfc5/raw/d8cd9afcc4ecf8557d1cf80d02946013c0dbdc68/freeport.sh | sh", + returnStdout: true + ).trim() + IMAGE_TAG = sh ( script: "echo '${env.JOB_NAME.toLowerCase()}' | tr '/' '-' | sed 's/%2f/-/g'", returnStdout: true @@ -21,7 +26,9 @@ pipeline { steps { echo 'Deploying...' - sh "docker run -v /var/run/docker.sock:/var/run/docker.sock -d --restart=always --network=james_default --name '${IMAGE_TAG}' -e NODE_ENV=test -e VIRTUAL_HOST=${IMAGE_TAG}.mustdash.es -p 3001:3001 ${IMAGE_TAG}" + echo 'Running on local port ${FREE_PORT}' + + sh "docker run -v /var/run/docker.sock:/var/run/docker.sock -d --restart=always --network=james_default --name '${IMAGE_TAG}' -e NODE_ENV=test -e VIRTUAL_HOST=${IMAGE_TAG}.mustdash.es -p ${FREE_PORT}:3001 ${IMAGE_TAG}" slackSend color: "good", message: "${env.JOB_NAME} deployed. Test it here: http://${IMAGE_TAG}.mustdash.es. Approve it here: ${RUN_DISPLAY_URL}." From 41acb4270eaba9370b66fc4e99efd9f846535c7d Mon Sep 17 00:00:00 2001 From: James Lambie Date: Thu, 28 Jun 2018 10:39:43 +1200 Subject: [PATCH 2/2] fix: enclose port in quotes --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5d58581..d0451b3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,7 +26,7 @@ pipeline { steps { echo 'Deploying...' - echo 'Running on local port ${FREE_PORT}' + echo "Running on local port ${FREE_PORT}" sh "docker run -v /var/run/docker.sock:/var/run/docker.sock -d --restart=always --network=james_default --name '${IMAGE_TAG}' -e NODE_ENV=test -e VIRTUAL_HOST=${IMAGE_TAG}.mustdash.es -p ${FREE_PORT}:3001 ${IMAGE_TAG}"