本文主要是介绍持续集成交付CICD:通过API方式上传Nexus制品,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
一、实验
1.通过API方式上传Nexus制品
二、问题
1.如何通过API方式上传PNG图片
2.如何通过API方式上传tar.gz 与 ZIP文件
3.如何通过API方式上传Jar file文件
4.如何通过API方式上传制品(maven类型的制品)文件
5.如何下载制品
一、实验
1.通过API方式上传Nexus制品
(1)Nexus选择API界面
(2)进入API界面
(2)指定仓库名
(3)选择上传的目录、文件、文件名
(4)移动到底部点击“Execute”
(5) 执行完成,返回204成功
curl -X 'POST' \'http://192.168.204.13:8081/service/rest/v1/components?repository=mylocalrepo' \-H 'accept: application/json' \-H 'Content-Type: multipart/form-data' \-H 'NX-ANTI-CSRF-TOKEN: 0.14963680641366128' \-H 'X-Nexus-UI: true' \-F 'raw.directory=/org/devops' \-F 'raw.asset1=@sonarqube-community-branch-plugin-1.12.0.jar' \-F 'raw.asset1.filename=sonarqube-community-branch-plugin-1.12.0'
(6)修改代码,添加认证信息,修改存储目录及文件,主机运行代码
curl -u admin:Admin123 -X 'POST' \
'http://192.168.204.13:8081/service/rest/v1/components?repository=mylocalrepo' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-H 'NX-ANTI-CSRF-TOKEN: 0.14963680641366128' \
-H 'X-Nexus-UI: true' \
-F 'raw.directory=/org/devops/aa' \
-F 'raw.asset1=@target/maven-test-1.0-SNAPSHOT.jar' \
-F 'raw.asset1.filename=maven-test-1.0-SNAPSHOT.jar'
(7)显示已上传成功
二、问题
1.如何通过API方式上传PNG图片
(1)修改代码
curl -u admin:Admin123 -X 'POST' \
'http://192.168.204.13:8081/service/rest/v1/components?repository=mylocalrepo' \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "raw.directory=/tmp" \
-F "raw.asset1=@123.png;type=image/png" \
-F "raw.asset1.filename=123.png"
2.如何通过API方式上传tar.gz 与 ZIP文件
(1)修改代码
curl -u admin:Admin123 -X 'POST' \
'http://192.168.204.13:8081/service/rest/v1/components?repository=mylocalrepo' \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "raw.directory=/tmp" \
-F "raw.asset1=@nexus-3.63.0-01-unix.tar.gz;type=application/x-gzip" \
-F "raw.asset1.filename=aaa.tar.gz"curl -u admin:Admin123 -X 'POST' \
'http://192.168.204.13:8081/service/rest/v1/components?repository=mylocalrepo' \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" -F "raw.directory=/tmp" \
-F "raw.asset1=@sonar-scanner-cli-4.8.0.2856-linux.zip;type=application/x-gzip" \
-F "raw.asset1.filename=sonar-scanner-cli-4.8.0.2856-linux.zip"
3.如何通过API方式上传Jar file文件
(1)修改代码
curl -u admin:Admin123 -X 'POST' \
'http://192.168.204.13:8081/service/rest/v1/components?repository=mylocalrepo' \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "raw.directory=/tmp" \
-F "raw.asset1=@aopalliance-1.0.jar;type=application/java-archive" \
-F "raw.asset1.filename=aopalliance-1.0.jar"
4.如何通过API方式上传制品(maven类型的制品)文件
(1)修改代码
curl -u admin:Admin123 -X 'POST' \
'http://192.168.204.13:8081/service/rest/v1/components?repository=mymavenrepo' \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "maven2.groupId=com.jenkinsci" \
-F "maven2.artifactId=devopsservice" \
-F "maven2.version=1.1.5" \
-F "maven2.packaging=jar" \
-F "maven2.asset1=@maven-test-1.0-SNAPSHOT.jar;type=application/java-archive" \
-F "maven2.asset1.extension=maven-test-1.0-SNAPSHOT" \
5.如何下载制品
(1)cURL
curl -u admin:Admin123 http://192.168.204.13:8081/repository/mymavenrepo/com/jenkins/devopstest/1.1.2/devopstest-1.1.2.jar
(2)Wget
wget --http-user=admin --http-passwd=Admin123 http://192.168.204.13:8081/repository/mymavenrepo/com/jenkins/devopstest/1.1.2/devopstest-1.1.2.jar
这篇关于持续集成交付CICD:通过API方式上传Nexus制品的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!