jenkins - Check within Jenkinsfile if docker service exists -
i setting ci pipelin means of jenkins.
i created following jenkinsfile:
pipeline { agent none stages { stage('build , push image') { agent { label 'man' } steps { sh 'docker image build -t login:stage .' sh 'docker tag login:stage 192.168.66.201:5000/login:stage' sh 'docker push 192.168.66.201:5000/login:stage' } } stage('create service') { agent { label 'dev' } steps { sh 'docker service create --name loginservice -p 40001:40001 --replicas=3 192.168.66.201:5000/login:stage' } } } }
i know, use components of docker (docker.withregistry) manually in first attempt knew happens.
but question how check in "create service"-stage, if docker service exists. if exists execute update statement.
you've got idea? using google or jenkins docs did not helped me..
one way doing this:
docker service ls | grep <service-name> && echo service-exists
if service name exists, echo execute. replace echo update command intend use.
Comments
Post a Comment