Commit d7bc3128 authored by 梦良's avatar 梦良

提交

parent e72c8a67
This diff is collapsed.
#!/usr/bin/env groovy
def projectProperties = [
[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '5']],
parameters([
string(name: 'DOCKER_USER', defaultValue: 'admin', description: 'docker用户名'),
string(name: 'DOCKER_PASSWORD', defaultValue: 'K2pass!!', description: 'docker用户密码'),
string(name: 'REGISTRY_URL', defaultValue: 'harbor.dev.k2paas.com', description: 'docker仓库地址')
]),
pipelineTriggers([
[
$class: 'GitLabPushTrigger',
branchFilterType: 'All',
triggerOnPush: false,
triggerOnMergeRequest: false,
triggerOpenMergeRequestOnPush: "never",
triggerOnNoteRequest: false,
triggerOnAcceptedMergeRequest: true,
noteRegex: "Jenkins please retry a build",
skipWorkInProgressMergeRequest: true,
ciSkip: true,
setBuildDescription: true,
addNoteOnMergeRequest: true,
addCiMessage: true,
addVoteOnMergeRequest: true,
acceptMergeRequestOnSuccess: true,
]
])
]
properties(projectProperties)
def label = "mypod-${UUID.randomUUID().toString()}"
podTemplate(label: label, cloud: 'kubernetes', containers: [
containerTemplate(name: 'golang', image: 'harbor.k2software.com.cn/library/golang:1.12-alpine', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'docker', image: 'harbor.k2software.com.cn/build/docker:latest', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'helm', image: 'harbor.k2software.com.cn/build/helm:v2.11.0', command: 'cat', ttyEnabled: true, envVars: [
envVar(key: 'KUBECONFIG', value: '/root/.kube/config')])
],
volumes: [
hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),
hostPathVolume(hostPath: '/root/.kube', mountPath: '/root/.kube'),
hostPathVolume(hostPath: '/root/.m2', mountPath: '/root/.m2'),
hostPathVolume(hostPath: '/root/.helm', mountPath: '/home/jenkins/.helm')
]) {
node(label) {
def version = "v6.0"
stage('checkout') {
checkout scm
sh 'printenv'
}
container('golang') {
stage('build') {
sh 'ls -al'
// 生成静态链接所有的库
sh 'CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -v -mod vendor -o k8s-console'
}
//stage('copy-front') {
// def dist_dir = "/mnt/k8s/online/${version}/front/k8s_console_front/dist"
// sh "cp -r $dist_dir frontend/"
//}
}
container('docker') {
//def tarName = "/mnt/k8s/online/${version}/images/paas-k8s-console_dev-${env.BUILD_ID}.tar"
stage('docker-login') {
//REGISTRY_URL私有仓库地址,也可使用官方地址:docker.io
sh "docker login -u ${params.DOCKER_USER} -p ${params.DOCKER_PASSWORD} ${params.REGISTRY_URL}"
}
stage('docker-build') {
sh "docker build . -t ${params.REGISTRY_URL}/paas-dev/paas-k8s-console:dev-${env.BUILD_ID}"
}
stage('docker-push') {
sh "docker push ${params.REGISTRY_URL}/paas-dev/paas-k8s-console:dev-${env.BUILD_ID}"
}
// stage('docker-save') {
// sh "rm -rf /mnt/k8s/online/${version}/images/paas-k8s-console_*.tar"
// sh "docker save ${params.REGISTRY_URL}/paas-dev/paas-k8s-console:dev-${env.BUILD_ID} > $tarName"
// }
stage('docker-rmi') {
sh "docker rmi ${params.REGISTRY_URL}/paas-dev/paas-k8s-console:dev-${env.BUILD_ID}"
}
}
//container('helm') {
// stage('helm deploy') {
// sh "sed -i \"s/tag: dev/tag: dev-${env.BUILD_ID}/g\" k8s-console-chart/values-dev.yaml"
// sh "helm upgrade --install k8s-console --namespace paas k8s-console-chart/ -f k8s-console-chart/values-dev.yaml"
//
// def previewTarget = "/mnt/k8s/online/${version}/charts"
// if(!fileExists("${previewTarget}")) {
// sh "mkdir -p ${previewTarget}"
// }
// sh "cp -r k8s-console-chart ${previewTarget}/"
// }
//}
}
}
// vim: ft=groovy
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment