pipeline {
agent{
label 'hw'
}
environment {
VERSION = sh(script: "echo `date '+%Y%m%d%H%M%S'`", returnStdout: true).trim()
}
stages {
stage('克隆代码'){
steps{
git branch: '${BRANCH}', credentialsId: '2ecdc3dd-3ea9-49e7-b7c9-878obcff0a2a', url: '${GITURL}'
}
}
stage('编译代码') {
steps {
sh """ ${COMMAND} """
}
}
stage('DockerFile') {
steps{
sh """ echo \"\n
FROM swr.cn-east-3.myhuaweicloud.com/dly-base/nginx:latest\n
WORKDIR /opt\n
ADD ./dist.tar ./\n
CMD [\\"nginx\\"]\" > ./Dockerfile """
}
}
stage('构建镜像') {
steps {
sh """ tar -cf ./dist.tar ./dist """
sh """ docker build -t swr.cn-east-3.myhuaweicloud.com/dly-test/${APPNAME}:${VERSION} . """
sh """ docker push swr.cn-east-3.myhuaweicloud.com/dly-test/${APPNAME}:${VERSION} """
sh """ rm -rf * """
}
}
stage('部署镜像'){
steps{
sh """ kubectl -n dsom-test set image deployment/${APPNAME} ${APPNAME}=swr.cn-east-3.myhuaweicloud.com/dly-test/${APPNAME}:${VERSION} """
}
}
}
}
标签:cn,APPNAME,前端,sh,steps,流水线,test,jenkins,stage
From: https://www.cnblogs.com/chenlifan/p/17352150.html