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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -