pipeline
{
agent any
environment
{
container_name
= 'osha-service-basic'
image_name
= 'localhost:5000/osha-service-basic'
port
= '18001'
}
stages
{
stage("checkout"){
steps
{
script
{
checkout([$class: 'GitSCM', branches
: [[name
: 'dev']], doGenerateSubmoduleConfigurations
: false, extensions
: [[$class: 'CloneOption', noTags
: true, shallow
: true, depth
: 1, honorRefspec
:true]], submoduleCfg
: [], userRemoteConfigs
: [[credentialsId
: 'r361468f-zbd4-289c-08a4-b45d1d4f86df',refspec
: '+refs/heads/dev:refs/remotes/origin/dev', url
: 'http://localhost:10080/root/osha.git']]])
}
}
}
stage("test"){
steps
{
sh
'cd $container_name && mvn clean package test'
}
}
stage("package"){
steps
{
sh
'''
for i in `docker ps | grep $container_name | awk '{print $1}'`
do
docker stop $i
docker rm $i
done
for i in `docker images | grep $image_name | awk '{print $3}'`
do
docker rmi $i
done
cd $container_name && mvn docker:build -DpushImage
'''
}
}
stage("deploy"){
steps
{
sh
'docker run -d --restart=always --network=host --name $container_name $image_name'
}
}
}
}
转载请注明原文地址:https://tech.qufami.com/read-5288.html