pipeline { agent any options { skipDefaultCheckout() disableConcurrentBuilds() timeout(time: 1, unit: 'HOURS') } environment { HARBOR_URL = 'xxxxx' HARBOR_USER = 'xxxxx' HARBOR_PWD = 'xxxxxxx' HARBOR_PROJECT_NAME = 'devops' } stages { stage('getcode') { agent { docker { image 'xxxxxxx/middleware/ubuntu1404' alwaysPull true reuseNode true } } steps { checkout scm echo "Successfully get gitlab code!!" } } stage('Build images and push images to Harbor') { agent { docker { image 'xxxxxxxx/big-data/devops-jenkins-slave' args '-v /var/run/docker.sock:/var/run/docker.sock' alwaysPull true reuseNode true } } steps{ script { // 获取提交地址及获取tag版本号 gitlab_url = "$env.gitlabSourceRepoSshUrl" push_type = "$env.gitlabActionType" split_url = gitlab_url.split("xxxxxxxxxxxxxxxx/") split_1 = split_url[-1] split_2 = split_1.split(".git") gitlab_name = split_2[0] tag_1 = "$env.gitlabSourceBranch" tag_2 = tag_1.split("/") tag_version = tag_2[-1] docker_name = gitlab_name.replaceAll("/","-") //构建及推送到Harbor仓库 build_docker_name = "$docker_name" sh "docker pull xxxxxx/middleware/ubuntu1404" sh "docker login -u xxxxxxx-p xxxx xxxxx.com" sh "docker build -t xxxxxxxx/devops/${build_docker_name}:${tag_version} ." println "xxxxxxxx/devops/${build_docker_name}:${tag_version} build success!" sh "docker push xxxxxxxx/devops/${build_docker_name}:${tag_version}" println "xxxx.com/devops/${build_docker_name}:${tag_version} push success!" // 推送到redmine创建任务 sh "curl \"http://redmine.xxxxx.com/create_deploy_issue?user_mail=${env.gitlabUserEmail}&project_full_id=${build_docker_name}&project_version=${tag_version}&gitlabSourceRepoHomepage=${env.gitlabSourceRepoHttpUrl}\"" } } } } }