Nexus 05 第二种方式 使用Jenkins Nexus插件上传制品
用插件的好处是可以使用DSL生成片段代码,但是代价是后期维护起来是很难受的,比如插件升级。后面可以使用api来实现上传,好处就是不需要依赖这些插件了,减少Jenkins的臃肿。
安装Nexus Artifact Uploader插件、使用片段生成器生成DSL。
插件上传和之前我们手动上传一样本质上还是调用了其API
下面是仓库信息
制品信息
stage('Nexus'){
steps{
script{
nexusArtifactUploader artifacts: [[artifactId: 'devops-lib',
classifier: '',
file: 'target/demo-0.0.1-SNAPSHOT.jar',
type: 'jar']],
credentialsId: 'ff93f4bf-9d8c-4fc2-bccd-3e614f10d643',
groupId: 'org.devops',
nexusUrl: '139.198.166.235:8082',
nexusVersion: 'nexus3',
protocol: 'http',
repository: 'devops-maven',
version: '1.1.1'
}
}
}
[Pipeline] { (Nexus)
[Pipeline] script
[Pipeline] {
[Pipeline] nexusArtifactUploader
Uploading artifact demo-0.0.1-SNAPSHOT.jar started....
GroupId: org.devops
ArtifactId: org.devops
Classifier:
Type: jar
Version: 1.1.1
File: demo-0.0.1-SNAPSHOT.jar
Repository:devops-maven
Uploading: http://139.198.166.235:8082/repository/devops-maven/org/devops/devops-lib/1.1.1/devops-lib-1.1.1.jar
10 % completed (1.7 MB / 17 MB).
20 % completed (3.4 MB / 17 MB).
30 % completed (5.1 MB / 17 MB).
40 % completed (6.8 MB / 17 MB).
50 % completed (8.5 MB / 17 MB).
60 % completed (10 MB / 17 MB).
70 % completed (12 MB / 17 MB).
80 % completed (14 MB / 17 MB).
90 % completed (15 MB / 17 MB).
100 % completed (17 MB / 17 MB).
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
这里只是上传制品,并不上传pom文件
进行优化, 将参数以变量的方式传递给函数。
最后写到共享库里面
//上传制品
def PushArtifacts(repoName,groupId, artifactId, version, type, filePath ){
nexusArtifactUploader artifacts: [[artifactId: "${artifactId}",
classifier: '',
file: "${filePath}",
type: "${type}"]],
credentialsId: '111b337e-89a0-4761-9ca3-6ee626ccd7a1',
groupId: "${groupId}",
nexusUrl: '192.168.1.200:8081',
nexusVersion: 'nexus3',
protocol: 'http',
repository: "${repoName}",
version: "${version}"
}
PushArtifacts('devops-maven','org.devops', 'devops-lib', '1.1.2', 'jar', 'target/demo-0.0.1-SNAPSHOT.jar' )
扩展: 可以在Jenkins页面添加参数, 让用户输入后进行发布。
pkg = sh returnStdout: true, script: """ ls target/ | grep -E "jar\$" """
pkg = pkg.trim()
println(pkg)
// //demo-0.0.1-SNAPSHOT.jar
// pkgName = pkg.split("-")[0]
// pkgType = pkg.split("\\.")[-1]
// println(pkgName + "| " + pkgType)
PushArtifacts( "${params.repoName}",
"${params.groupId}",
pkgName,
"${params.pkgVersion}",
pkgType,
"target/${pkg}"
)
要发布的时候可以直接下载,要下载用的就是这个链接
发布制品
安装Maven Artifact ChoiceListProvider (Nexus)插件
这个可以以参数的形式展现在Jenkins上面,然后选择生成包
这样在构建的时候就可以指定发哪个包了
目录 返回
首页