Nexus 制品库管理实践03 raw类型的仓库
raw可以理解为本地文件存储类型,就相对于一块存储,可以往里面传入任何的包,制品和依赖是不同的,依赖是要被其他包所引用的,如maven。制品是要发布的包,这个就不需要依赖了。所以制品可以放到raw类型仓库就行了。
本地仓库类型有很多,这里可以选择,raw是最普通的格式了,可以理解为文件存储格式。
创建raw类型的仓库,这就是一个文件存储,所有的包都传到这上面来。如果是maven类型的制品,直接用<dependency>引入。maven类型是依赖,是制品传上去之后需要被依赖。
如果只是将制品发布,作为服务,不需要被其他人引用,可以做为raw类型的
新建raw类型的仓库
上传制品
curl -u admin:admin123 如果Nexus开启了认证需要配置认证信息才能正常访问。
curl -X POST "http://139.198.166.235:8082/service/rest/v1/components?repository=devops-repo" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "raw.directory=/acmp/acmp-myapp-service/1.1.1" \
-F "raw.asset1=@target/demo-0.0.1-SNAPSHOT.jar;type=application/java-archive" \
-F "raw.asset1.filename=acmp-myapp-service-1.1.1.jar" \
-u admin:admin123
现在规范化一些,传到固定的仓库:devops-repo,这个仓库存放的是每个组的包
/acmp/acmp-myapp-service/1.1.1/acmp-myapp-service-1.1.1.jar
如果是前端服务:
/acmp/acmp-myapp-web/1.1.1/acmp-myapp-web-1.1.1.zip
stage('PushArtifacts'){
steps{
script{
repository = "devops-repo"
version = "1.1.2"
project = "${env.JOB_NAME}".split("-")[0]
directory = "${project}/${env.JOB_NAME}/${version}"
pkg = sh returnStdout: true, script: """ ls target/ | grep -E "jar\$" """
asset = pkg - "\n"
filename = "${env.JOB_NAME}-${version}.jar"
println(filename)
sh "mv target/${asset} target/${filename} && ls target/"
script{
withCredentials([usernamePassword(credentialsId: 'ff93f4bf-9d8c-4fc2-bccd-3e614f10d643', passwordVariable: 'passwd', usernameVariable: 'user')]) {
nexus.PushRawArtifactsByApi(repository,directory,filename,user,passwd)
}
}
}
}
}
def PushRawArtifactsByApi(repository,directory,filename,user,passwd){
sh """
curl -X POST "http://139.198.166.235:8082/service/rest/v1/components?repository=${repository}" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "raw.directory=${directory}" \
-F "raw.asset1=@target/${filename};type=application/java-archive" \
-F "raw.asset1.filename=${filename}" \
-u "${user}":"${passwd}"
"""
}
[Pipeline] { (PushArtifacts)
[Pipeline] script
[Pipeline] {
[Pipeline] sh
+ ls target/
+ grep -E 'jar$'
[Pipeline] echo
acmp-myapp-service-1.1.2.jar
[Pipeline] sh
+ mv target/demo-0.0.1-SNAPSHOT.jar target/acmp-myapp-service-1.1.2.jar
+ ls target/
acmp-myapp-service-1.1.2.jar
classes
demo-0.0.1-SNAPSHOT.jar.original
generated-sources
generated-test-sources
maven-archiver
maven-status
surefire-reports
test-classes
[Pipeline] script
[Pipeline] {
[Pipeline] withCredentials
Masking supported pattern matches of $passwd
[Pipeline] {
[Pipeline] sh
Warning: A secret was passed to "sh" using Groovy String interpolation, which is insecure.
Affected argument(s) used the following variable(s): [passwd]
See https://jenkins.io/redirect/groovy-string-interpolation for details.
+ curl -X POST 'http://139.198.166.235:8082/service/rest/v1/components?repository=devops-repo' -H 'accept: application/json' -H 'Content-Type: multipart/form-data' -F raw.directory=/acmp-myapp-service/1.1.2 -F 'raw.asset1=@target/acmp-myapp-service-1.1.2.jar;type=application/java-archive' -F raw.asset1.filename=acmp-myapp-service-1.1.2.jar -u admin:****
可以看到一个项目acmp下面有很多的服务acmp-myapp-service等等......,每个服务下面有不同版本的包。
如果是静态项目,就是创建静态的压缩包
[root@jenkins-agent devops-web-service]# cd dist/
[root@jenkins-agent dist]# tar zcf dist.tar.gz *
[root@jenkins-agent dist]# ls
dist.tar.gz index.html static
curl -X POST "http://139.198.166.235:8082/service/rest/v1/components?repository=devops-repo" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "raw.directory=/devops/devops-web-service" \
-F "raw.asset1=@dist/dist.tar.gz;type=application/x-gzip" \
-F "raw.asset1.filename=devops-web-service-1.1.1.tar.gz" \
-u admin:admin123
目录 返回
首页