Jenkins Pipeline 脚本

我常说 2019 年对于我来说是转折性的一年,提前完成了前半辈的很多事情。有些事还是要提前规划,要不然轮到身上的时候会措手不及。这次疫情很多人都会在家,很多人羡慕自由职业者,然并卵,这下应该都能体会到了做自由职业者也需要自律,要不然根本弄不成事。

有人说疫情之后会面临很多裁员,但是在我看来也许机会更多了。你看看这次疫情,许多线下实体店都倒闭了,比如KTV,饭店,酒店等等。就连学生上课都成了线上授课模式,这也充分说明了当今时代是互联网的天下。如果你入了互联网这一行,那么机会还是挺多的,不要灰心。经我交流和查看,互联网平均薪资仍然是处于TOP端,所以,2020,该给自己设个目标了。

2020,我劝大家好好工作,好好干副业。意外和明天永远不知道哪个先到来。


最近在家远程办公,因工作当中需要用到 pipeline 脚本,所以特意学习了一下。jenkins pipeline 通用脚本:

pipeline {
    agent any
   tools {
        //工具必须预先在jenkins中预配置
        maven 'mvn'
        jdk 'jdk'
    }
    stages {
        stage('Env') {
           
            steps {
                sh 'printenv'
            }
        }
        stage('git') {
         steps{
           checkout([$class: 'GitSCM', branches: [[name: '*/develop']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '18980d0a-1ae4-443b17dc687b1', url: 'https://CFAI_the_best/codeflag-basis.git']]])
         }
   }
        stage('mvn install') {
          
           steps {
            
              sh 'cd /var/lib/jenkins/workspace/k8s-test-basis/src/main/resources && mv application.test.properties application.properties'
              
              sh 'mvn clean install'
              
           }
          
       }
        stage('docker') {
           
           steps {
               
               sh 'cd /var/lib/jenkins/workspace/k8s-test-basis/target '
              sh '''
      REPOSITORY=172.18.0.218/codeflagtest/codeflag-basis:${BUILD_ID}
        pwd
        echo '
        FROM 172.18.0.218/codeflagtest/tomcat
      RUN rm -rf /usr/local/tomcat/webapps/ROOT
        RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
  && echo 'Asia/Shanghai' >/etc/timezone
          ADD target/basic-0.0.1-SNAPSHOT.war /usr/local/tomcat/webapps/ROOT.war
        ' > Dockerfile
        docker build -t $REPOSITORY .
        docker login 172.18.0.218 -u admin -p Harbor123456
        docker push $REPOSITORY
      
        '''
           }
          
        }
                stage('deploy') {
          
           steps {
               sh ' REPOSITORY=172.18.0.218/codeflagtest/codeflag-basis:${BUILD_ID}'
              sh 'kubectl get pod'
              sh '''
 cat << EOF > basis.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: basis
spec:
  replicas: 2
  selector:
    matchLabels:
      app: basis
  template:
    metadata:
      labels:
        app: basis
    spec:
      containers:
      - name: basis
        image: 172.18.0.218/codeflagtest/codeflag-basis:${BUILD_ID}
      
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
        volumeMounts:
          - name: pvc-nas
            mountPath: "/home/www/test"
      volumes:
        - name: pvc-nas
          persistentVolumeClaim:
            claimName: pvc-nas
      imagePullSecrets:
        - name: registry-secret

---
apiVersion: v1
kind: Service
metadata:
  name: basis
spec:
  ports:
  - port: 80
    targetPort: 8080
    name: basis
  selector:
    app: basis
  type: LoadBalancer
EOF

kubectl apply -f basis.yaml
              
              '''
              
           }
          
       }
    }

}
发布了354 篇原创文章 · 获赞 2 · 访问量 1万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览