举几个例子:
每隔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}
'''
}
}
}
}