声明式语法重写基于容器CICD构建流水线
调试了一下午,一句话都不想说了,看代码。 ~~~~~
参考文档
https://blog.csdn.net/weixin_42010394/article/details/90670945
实践代码
def server = "cloudslave-${UUID.randomUUID().toString()}" pipeline{ agent{ kubernetes{ label "${runserver}" cloud 'kubernetes' yaml ''' apiVersion: v1 kind: Pod metadata: labels: jenkins: slave namespace: jenkins spec: containers: - name: jnlp env: - name: PATH value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/apache-maven-3.5.0/bin - name: CLASS_PATH value: /docker-java-home/jre/lib/rt.jar:/docker-java-home/jre/lib/dt.jar:/docker-java-home/jre/lib/tools.jar image: registry.it.com/jenkins/slave-maven-ant-sonar-jdk8u111:latest imagePullPolicy: IfNotPresent resources: limits: cpu: '8' memory: 16Gi requests: cpu: '8' memory: 16Gi tty: true volumeMounts: - mountPath: /data/jenkins name: volume-1 - mountPath: /etc/data/m2repository name: volume-2 - mountPath: /home/jenkins name: workspace-volume - mountPath: /var/run/secrets/kubernetes.io/serviceaccount name: default-token-fcbxp readOnly: true workingDir: /home/jenkins nodeSelector: build-infra: 'true' node-role.kubernetes.io/compute: 'true' volumes: - name: volume-2 persistentVolumeClaim: claimName: m2repo - name: volume-1 persistentVolumeClaim: claimName: jenkins - emptyDir: {} name: workspace-volume - name: default-token-fcbxp secret: defaultMode: 420 secretName: default-token-fcbxp ''' } } options { skipDefaultCheckout() } stages{ //下载代码 stage("GetCode"){ steps{ timeout(time:5, unit:"MINUTES"){ script{ ws("${workspace}"){ echo "Get Code" } } } } } //构建 stage("Build"){ steps{ timeout(time:10, unit:"MINUTES"){ script{ ws("${workspace}"){ echo '应用打包' } } } } } } }
关注公众号