81 lines
3.2 KiB
Plaintext
81 lines
3.2 KiB
Plaintext
def projectProperties = [
|
|
[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '5']],
|
|
parameters([
|
|
string(name: 'BRANCH_NAME', defaultValue: 'master', description: '代码分支'),
|
|
string(name: 'CLEAN_FLAG', defaultValue: "false", description: '是否清理工作空间'),
|
|
string(name: 'VERSION', defaultValue: "1.0", description: '包版本'),
|
|
string(name: 'GENERATE_IMAGES_LISTS', defaultValue: "true", description: '是否生成images_list文件'),
|
|
string(name: 'INCLUDE_APPS_IMAGES', defaultValue: "true", description: '是否包含应用镜像'),
|
|
string(name: 'DEST_PATH_PREFIX', defaultValue: "/var/jenkins_home", description: '打包文件保存目录')
|
|
])
|
|
]
|
|
|
|
properties(projectProperties)
|
|
|
|
node('master') {
|
|
|
|
//部署文件路径
|
|
DEPLOY_PROJECT_PATH="${WORKSPACE}/ccyunchina-deploy";
|
|
|
|
//镜像文件保存目录
|
|
IMAGES_PATH="${DEPLOY_PROJECT_PATH}/images"
|
|
|
|
//基础镜像文件列表
|
|
IMAGES_LIST="${DEPLOY_PROJECT_PATH}/tools/images/images_list"
|
|
|
|
//应用商店镜像文件列表
|
|
APPS_IMAGES_LIST="${DEPLOY_PROJECT_PATH}/tools/images/apps_images_list"
|
|
|
|
//打包文件保存目录
|
|
DEST_PATH="${DEST_PATH_PREFIX}/k8s_data/${VERSION}"
|
|
|
|
//源harobr镜像库地址
|
|
HARBOR_SRC="dev-docker-registry.ccyunchina.com"
|
|
|
|
|
|
stage('拉取k8s部署文件') {
|
|
if("${CLEAN_FLAG}" == "true"){
|
|
cleanWs()
|
|
}
|
|
dir(DEPLOY_PROJECT_PATH){
|
|
git branch: "${BRANCH_NAME}", url: 'https://gitlink.org.cn/toyangdon/ccyunchina-deploy.git'
|
|
}
|
|
}
|
|
|
|
if( "${GENERATE_IMAGES_LISTS}" == "true" ){
|
|
stage('生成基础镜像列表'){
|
|
sh "grep '_image:' -hr ${DEPLOY_PROJECT_PATH}/roles ${DEPLOY_PROJECT_PATH}/group_vars|cut -d':' -f2,3|sed 's/\"//g'|sed 's/ //g' |sort -u >${IMAGES_LIST} "
|
|
}
|
|
}
|
|
|
|
stage('拉取并打包基础镜像') {
|
|
sh "docker login -u toyangdon -pyd880309"
|
|
sh "apt install pigz -y"
|
|
if( "${INCLUDE_APPS_IMAGES}" == "true" ){
|
|
sh "cat ${APPS_IMAGES_LIST} >> ${IMAGES_LIST}"
|
|
sh "rm -f ${APPS_IMAGES_LIST}"
|
|
}
|
|
sh "sh ${DEPLOY_PROJECT_PATH}/tools/images/images_batch_save.sh ${IMAGES_PATH} ${HARBOR_SRC} ${IMAGES_LIST}"
|
|
|
|
}
|
|
|
|
stage('拉取并导出ansible镜像') {
|
|
sh "docker pull dev-docker-registry.ccyunchina.com/toyangdon/ansible:latest"
|
|
sh "docker save dev-docker-registry.ccyunchina.com/toyangdon/ansible:latest -o ccyunchina-deploy/ansible_image.tar"
|
|
}
|
|
|
|
|
|
|
|
stage('打包部署文件') {
|
|
sh "rm -rf ccyunchina-deploy/.git"
|
|
sh "tar --use-compress-program=pigz -cvpf ccyunchina-deploy.tar.gz ccyunchina-deploy"
|
|
}
|
|
|
|
stage('归档部署文件'){
|
|
//根据版本号创建目录,如果目录已经存在则报错退出
|
|
sh "mkdir -p ${DEST_PATH}"
|
|
sh "cp ccyunchina-deploy.tar.gz ${DEST_PATH}/"
|
|
}
|
|
}
|
|
|