Created
April 30, 2018 14:43
-
-
Save caiogallo/aa307882f149b347c7361ca26df6817c to your computer and use it in GitHub Desktop.
Pipeline do jenkins para deploy com docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node{ | |
stage('git pull') { | |
git url: 'https://github.com/caiogallo/ci-sample.git', branch: 'master' | |
} | |
stage('build'){ | |
withMaven(maven: 'maven'){ | |
sh 'mvn clean package' | |
} | |
} | |
stage('Build docker images'){ | |
docker.withTool('docker'){ | |
def app = docker.build 'ci-app-image' | |
} | |
} | |
stage('Stop and remove containers'){ | |
docker.withTool('docker'){ | |
sh ''' | |
NAME=ci-sample | |
CONTAINER=`docker ps -a -q -f name=$NAME` | |
echo container: $CONTAINER | |
if [ -z $CONTAINER ] | |
then | |
echo "container $NAME not running" | |
else | |
docker stop $CONTAINER | |
docker rm $CONTAINER | |
fi | |
''' | |
} | |
} | |
stage('Start containners'){ | |
docker.withTool('docker'){ | |
docker.image("ci-app-image") | |
.run('-p 8090:8080 --name ci-sample') | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment