此模板可用于下载代码、编译。
pipeline {
agent { // 2~33行 编译环境初始化
kubernetes {
label "${UUID.randomUUID().toString()}"
yaml """
metadata:
labels:
some-label: some-label-value
class: KubernetesDeclarativeAgentTest
namespace: scm
spec:
nodeSelector:
jenkins-ci: "true"
containers:
- name: prepare
image: hub.hobot.cc/builder/cicd-common-tool:v12
command:
- cat
tty: true
env:
- name: CONTAINER_ENV_VAR
value: prepare
"""
}
}
options {
gitLabConnection('Gitlab connector by hobot.ci')
}
parameters { //定义参数,
string defaultValue: '', description: 'Enter gitlabSourceRepoSshUrl', name: 'gitlabSourceRepoSshUrl', trim: true
string defaultValue: '', description: 'Enter gitlabSourceBranch', name: 'gitlabSourceBranch', trim: true
}
environment { //环境变量
LANG = 'en_US.UTF-8'
}
stages{
stage('lanuch') {
steps {
container('prepare') { //括号里的是15行定义的 name
script {
sh 'env'
get_code()
}
}
}
}
stage('building') { //57~65 行是编译环节
steps {
container('prepare') { //括号里的是15行定义的 name
script {
sh 'bash -ex build.sh' //执行编译脚本,实际编译时需要修改
}
}
}
}
}
}
//函数,pipline中通过函数名调用,没有特殊需求不用修改
def get_code() {
echo "get code process"
checkout([
$class: 'GitSCM',
branches: [[name: "origin/${env.gitlabSourceBranch}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
[$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: true, recursiveSubmodules: true, reference: '', trackingSubmodules: true],
[$class: 'AuthorInChangelog'],
[$class: 'UserIdentity', email: 'xxxx@horizon.ai', name: 'xxxx'],
],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'XXXXX', url: "${env.gitlabSourceRepoSshUrl}"]]
])
}