使用Jenkins 插件Nexus artifact uploader 上传 .jar, .zip. .gzip. .tar等制品
Jenkins 使用自由风格配置构建时:
配置如下:
Credentials 为上传Nexus服务器的用户认证信息 ,需要在Jenkins 凭据中配置
Repository: 为Nexus上的仓库名称
如果为.tar结尾的包,可能需要在nexus repositories 配置中取消勾选(根据nexus版本不同) :
Validate that all content uploaded to this repository is of a MIME type appropriate for the repository format
否则会报错:
Failed to deploy artifacts: Could not transfer artifact … from/to maven-releases … Return code is: 400, ReasonPhrase:Detected content type [application/gzip, application/gzip-compressed, application/gzipped, application/x-gunzip, application/x-gzip, application/x-gzip-compressed, gzip/document], but expected [application/x-tar]: (3.37版本)
或:
Failed to deploy artifacts: Could not transfer artifact … from/to … Failed to transfer file: …tar. Return code is: 400, ReasonPhrase:Bad Request. (3.28.1版本)
按照规则正确配置后我遇到的报错:
Failed to deploy artifacts: Could not transfer artifact …tar:1.0.1 from/to maven-release (http://192.100.30.160:8081/repository/maven-release): Connection reset
使用pipeline方式配置:
stage('上传') {
steps {
nexusArtifactUploader artifacts: [
[
artifactId: 'aaa',
classifier: '', ##相当于给上传的制品添加后缀
file: 'XXX.tar', ##上传的文件,可以写绝对路径,这里是在workspace下
type: 'tar' ##上传包的后缀 也可以是 tar.gz
]
],
credentialsId: 'devops', ##Jenkins 凭据ID
groupId: 'com.src.XXXX',
nexusUrl: '192.100.30.160:8081',
nexusVersion: 'nexus3',
protocol: 'http',
repository: 'maven-release',
version: '1.0.1'
}
}
使用 pipeline 无任何报错信息输出如下:
报错原因:
Jenkins中的用户凭据有问题,用户为ldap用户, Nexus集成了Ldap, 没有给ldap用户授权,导致认证失败 ,在nexus log/request.log 中有报错信息:
192.100.30.162 - user [21/May/2022:15:10:01 +0800] “PUT /repository/…-1.0.1.tar HTTP/1.1” 403 7792793 0 1 “Aether” [qtp1999153675-13260]
上传时权限被拒绝,但是该报错信息并没有返回Jenkins终端,导致制品上传失败但是jenkins结果仍然是success