目录
一、实验
1.Jenkins使用CD流水线下载Nexus制品
(1)Jenkins新建CD流水线
(2)新建视图
(3)查看视图
(4)添加字符参数
(5)添加选项参数
(6)修改流水线代码
"PullArtifacts"阶段通过2个if条件判断项目类型,下载制品函数PullArtifacts()通过wget方式下载制品
bash
pipeline {
agent { label "build" }
stages{
stage("PullArtifacts"){
steps{
script{
repoName = "${JOB_NAME}".split("/")[0]
projectName ="${JOB_NAME}".split("/")[-1].split("_")[0]
if ("${env.projectType}" == "maven"){
type="jar"
}
if ("${env.projectType}" == "npm"){
type="tar.gz"
}
PullArtifacts("${env.releaseVersion}",projectName,repoName,type)
}
}
}
stage("DeployHost"){
steps{
script{
print("DeployHost")
}
}
}
stage("ServiceCtrl"){
steps{
script{
print("ServiceCtrl")
}
}
}
stage("HealthCheck"){
steps{
script{
print("HealthCheck")
}
}
}
}
}
//下载制品
def PullArtifacts(version,projectName,repoName,type){
repoUrl = "http://192.168.204.13:8081/repository"
pkgPath = "${repoUrl}/${repoName}/${projectName}/${version}/${projectName}-${version}.${type}"
sh "wget --http-user=admin --http-passwd=Admin123 ${pkgPath} "
}
(7)手动构建CD流水线项目
(8)Blue Ocean 查看
(9)查看日志,已成功下载制品
(10)查看Nexus,下载的制品与仓库里的制品保持一致