一、在jenkins下创建job
### --- 创建view item
~~~ Jenkins——>Dashboard——>+号——>View name:uat——> List View——>ok——>ok——>END
### --- 创建Jobs
~~~ Jenkins——>Dashboard——>New Item——>Enter an item name:nodejs-uat——>Copy from :nodejs-demo——>OK——>
~~~ ——>删除一些配置变量:BRANCH、REPO_URL、BUILD_COMMAND、DEPLOY——>
~~~ ——>更改一些配置变量:Hidden Parameter——>Name:CLUSTER——>Default Value:uat——>
~~~ ——>更改一些配置变量:Hidden ParameterName:NAMESPACE——>Default Value:nodejs-uat——>
~~~ ——>添加配置变量:Active Choices Reactive Parameter——>Name:IMAGE_TAG
~~~ ——>Groovy Script:见如下配置参数——>Fallback Script:Groovy Script:returm 'error'
~~~ ——>Choice Type:Single Select——>引用变量:Referenced parameters:REGISTRY_DIR,IMAGE_NAME——>
def get_tags = [ "bash", "-c", "aliyun cr GetRepoTags --RepoNamespace ${REGISTRY_DIR} --RepoName ${IMAGE_NAME} | jq ' .data.tags[].tag' -r" ]
return get_tags.execute().text.tokenize('\n')
### --- ——>更改流水线配置:
~~~ Pipeline——>Definition:Pipeline script:Hello World:参数见下文——>Save
pipeline {
agent any
stages {
stage('Hello') {
steps {
sh """
echo ${IMAGE_TAG}
"""
}
}
}
}
二、build构建nodejs-demo
### --- build构建nodejs-demo
~~~ 查看是否可以获取到镜像
~~~ 查看是否可以打印出来tags
SuccessConsole Output
Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /root/.jenkins/workspace/nodejs-uat
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Hello)
[Pipeline] sh
+ echo 20210623-153619-87148f1-master
20210623-153619-87148f1-master // tags打印完成
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
三、创建uat集群配置:在jenkins所在宿主机配置
### --- 创建multi-cluster.yaml文件
[root@k8s-node01 ~]# vim /mnt/.kube/multi-cluster.yaml
ap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