pipeline{ agent any options { timestamps() // daysToKeepStr:, numToKeepStr: buildDiscarder(logRotator(daysToKeepStr: '7', numToKeepStr: '10')) } environment { // Git Info 需修改 __Git_Addr = 'http://git.keyfil.com/saas-back-end/qifu-saas-eg.git' __Git_Name = "${__Git_Addr.split('/')[-1].split('.git')[0]}" wxbot_id = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=9245d561-9d29-4d58-be39-5edc3dba293d' } parameters { // TAG //gitParameter(name:'BRANCH', type: 'PT_TAG', defaultValue: 'master', sortMode: 'DESCENDING_SMART', selectedValue: 'TOP', quickFilterEnabled: true) gitParameter branch: '', branchFilter: '.*', defaultValue: 'master', listSize: '', name: 'BRANCH', quickFilterEnabled: true, selectedValue: 'NONE', sortMode: 'NONE', tagFilter: '*', type: 'GitParameterDefinition' } stages{ stage("Git Code") { steps{ deleteDir() script{ checkout([$class: 'GitSCM', branches: [[name: "${BRANCH}"]], extensions: [], userRemoteConfigs: [[credentialsId: 'gitlab', url: "${__Git_Addr}"]]]) } } } stage("Build") { steps{ dir("${WORKSPACE}"){ script { sh "source /etc/profile;mvn clean package -P development -DskipTests -U" } } } } stage("Docker Build&Push&Publish") { steps{ dir("${WORKSPACE}"){ script{ jar_name = sh (returnStdout: true, script: 'ls qifu-saas-eg-service/target/ | grep \'.jar\' | grep -v \'sources\' | head -n 1').trim() sh """ rm Dockerfile -rf cp /opt/data/oom-test.sh /opt/data/mc . cp /opt/data/apache-skywalking-java-agent-9.4.0.tgz . JAR_NAME=${jar_name} echo 'FROM ubuntu:16.04 as jar' >> Dockerfile echo 'WORKDIR /' >> Dockerfile echo 'RUN apt-get update -y' >> Dockerfile echo 'RUN DEBIAN_FRONTEND=noninteractive apt-get install -y wget' >> Dockerfile echo 'RUN wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.20.0/jmx_prometheus_javaagent-0.20.0.jar' >> Dockerfile echo 'FROM openjdk:11' >> Dockerfile echo \"ADD qifu-saas-eg-service/target/\${JAR_NAME} /app/\${JAR_NAME}\" >> Dockerfile echo 'COPY --from=jar /jmx_prometheus_javaagent-0.20.0.jar /app/jmx_prometheus_javaagent-0.20.0.jar' >> Dockerfile echo 'COPY oom-test.sh /app/' >> Dockerfile echo 'COPY mc /usr/local/sbin/' >> Dockerfile echo 'ADD apache-skywalking-java-agent-9.4.0.tgz /app/' >> Dockerfile echo 'ENV TZ=Asia/Shanghai' >> Dockerfile echo 'EXPOSE 8088' >> Dockerfile echo 'EXPOSE 8933' >> Dockerfile echo 'ENTRYPOINT ["java", "-XX:+HeapDumpOnOutOfMemoryError", "-XX:HeapDumpPath=/app/dump.hprof", "-XX:+ExitOnOutOfMemoryError", "-XX:OnOutOfMemoryError=/app/oom-test.sh", "-javaagent:/app/skywalking-agent/skywalking-agent.jar", "-Dskywalking.agent.service_name=qifu-saas-eg-test", "-Dskywalking.collector.backend_service=oap.qifu.svc:11800", "-jar", "-javaagent:/app/jmx_prometheus_javaagent-0.20.0.jar=8088:/app/jmx_exporter.yaml", "/app/${jar_name}"]' >> Dockerfile """ sh ''' tag=`date +%s`;docker build -t harbor.qifu.com/qifu-test/qifu-saas-eg:${VERSION}-${tag} . docker push harbor.qifu.com/qifu-test/qifu-saas-eg:${VERSION}-${tag} kubectl set image deployment/qifu-saas-eg qifu-saas-eg=harbor.qifu.com/qifu-test/qifu-saas-eg:${VERSION}-$tag -n qifu ''' } } } } } post { failure{ qyWechatNotification mentionedId: '', mentionedMobile: '16620101812', moreInfo: '', webhookUrl: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=9245d561-9d29-4d58-be39-5edc3dba293d' } } }