jenkins自动部署

举几个例子:
每隔5分钟构建一次
H/5 * * * *

每两小时构建一次
H H/2 * * *

每天中午12点定时构建一次
H 12 * * *

每天下午18点定时构建一次
H 18 * * *

在每个小时的前半个小时内的每10分钟
H(0-29)/10 * * * *

每两小时45分钟,从上午9:45开始,每天下午3:45结束
45 9-16/2 * * 1-5

每两小时一次,每个工作日上午9点到下午5点(也许是上午10:38,下午12:38,下午2:38,下午4:38)
H H(9-16)/2 * * 1-5

在这里插入图片描述

pipeline {
    agent any
    environment { 
		def imageNamecdp = "aiot-web-2"
    }
    tools { 
        nodejs "Nodejs"
    }
    stages {
        stage('check out') {
            steps {
                 checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'Gitlab', url: 'http://121.36.94.227:9000/cig/aiot/aiot-phase2-web.git']]])        }
                }
                stage('building project') {
            steps {
                sh '''
                        
                    #打包
                    npm install
                    npm run build 
			        #删除旧jar包,拷贝新jar包
			        rm -rf /mnt/aiot-web/aiot-phase2-web/dist
			        cp -r dist/ /mnt/aiot-web/aiot-phase2-web
                    
                    containerStr=`docker ps -a | grep -w ${imageNamecdp} | awk '{print $1}'`
					imageStr=`docker images | grep -w ${imageNamecdp}  | awk '{print $3}'`
					echo "container id:$containerStr"
					echo "image id:$imageStr"
					
					if [ "$imageStr" !=  "" ] ; then
						if [ "$containerStr" !=  "" ] ; then
							#停掉容器
							docker stop `docker ps -a | grep -w ${imageNamecdp}  | awk '{print $1}'`
						
							#删除容器
							docker rm `docker ps -a | grep -w ${imageNamecdp}  | awk '{print $1}'`
						
							#删除镜像
							docker rmi --force ${imageNamecdp}
						else
							 #删除镜像
							docker rmi --force ${imageNamecdp}
						
						fi
					 fi
					
					
					#打包镜像					
					cd /mnt/aiot-web/aiot-phase2-web
					
					docker build --no-cache -t ${imageNamecdp} .
					
					docker run -d -p 5009:80 --name=aiot-web-phase2 ${imageNamecdp}
				'''	
            }
        }
    }
}

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端段

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值