小编And*_*réw的帖子

如果存在docker服务,请在Jenkinsfile中检查

我正在通过Jenkins建立CI Pipelin.

我创建了以下Jenkinsfile:

pipeline {
agent none

stages {
    stage('Build and 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'
        }
    }
} 
}
Run Code Online (Sandbox Code Playgroud)

我知道,我可以使用docker(docker.withRegistry)的组件,但我喜欢在第一次尝试时手动完成,以确切知道会发生什么.

但我的问题是如果已经存在docker服务,如何检查"创建服务"-Stage.如果他存在,我喜欢执行更新声明.

你有什么想法吗?使用谷歌或詹金斯文档并没有真正帮助我..

continuous-integration jenkins docker jenkins-pipeline

2
推荐指数
1
解决办法
1277
查看次数