Commit 16f2796b authored by 卢浩元's avatar 卢浩元

add kaniko jenkins

parent 1ce7ad9b
#!/usr/bin/env groovy
def projectProperties = [
[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '5']],
parameters([
string(name: 'DOCKER_USER', defaultValue: '', description: 'docker用户名'),
string(name: 'DOCKER_PASSWORD', defaultValue: '', description: 'docker用户密码'),
string(name: 'REGISTRY_URL', defaultValue: 'docker.io', description: 'docker仓库地址')
])
]
properties(projectProperties)
def label = "mypod-${UUID.randomUUID().toString()}"
podTemplate(label: label, cloud: 'kubernetes', containers: [
containerTemplate(name: 'maven', image: 'harbor.k2software.cn/build/maven:3.6.0-jdk-8', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'kaniko', image: 'harbor.k2software.cn/build/kaniko-executor:v1.3.0', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'helm', image: 'harbor.k2software.cn/build/helm:v3.2.2', command: 'cat', ttyEnabled: true, envVars: [
envVar(key: 'KUBECONFIG', value: '/root/.kube/config')])
],
volumes: [
hostPathVolume(hostPath: '/root/.kube', mountPath: '/root/.kube'),
hostPathVolume(hostPath: '/root/.m2', mountPath: '/root/.m2'),
secretVolume(secretName: 'jenkins-docker-cfg', mountPath: '/kaniko/.docker')
],
annotations: [
podAnnotation(key: "sidecar.istio.io/inject", value: "false")
]
) {
node(label) {
def gitCommit
def shortGitCommit
def previousGitCommit
container('maven') {
stage('checkout') {
checkout scm
sh 'printenv'
gitCommit = sh(script: "git rev-parse HEAD", returnStdout: true).trim()
shortGitCommit = "${gitCommit[0..10]}"
previousGitCommit = sh(script: "git rev-parse ${gitCommit}~", returnStdout: true)
echo "gitCommit = ${gitCommit}"
echo "shortGitCommit = ${shortGitCommit}"
echo "previousGitCommit = ${previousGitCommit}"
}
stage('pacakge') {
sh 'mvn clean package -Dmaven.test.skip=true -s ./settings.xml'
}
}
container('kaniko') {
stage('image-build') {
sh "/kaniko/executor -f `pwd`/Dockerfile -c `pwd` --insecure --skip-tls-verify --cache=true --destination=${params.REGISTRY_URL}/library/k8s-example:${shortGitCommit}"
}
}
container('helm') {
stage('helm deploy') {
sh label: "replace config", script: """
sed -i s#lusyoe/k8s-example#${params.REGISTRY_URL}/library/k8s-example:${shortGitCommit}#g charts/values.yaml
"""
sh "helm upgrade --install k8s-example charts/ --kubeconfig=/root/.kube/config"
}
}
}
}
// 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