持续集成交付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界面

持续集成交付CICD:通过API方式上传Nexus制品_第1张图片

(2)进入API界面持续集成交付CICD:通过API方式上传Nexus制品_第2张图片


(2)指定仓库名

持续集成交付CICD:通过API方式上传Nexus制品_第3张图片

(3)选择上传的目录、文件、文件名持续集成交付CICD:通过API方式上传Nexus制品_第4张图片

(4)移动到底部点击“Execute”

持续集成交付CICD:通过API方式上传Nexus制品_第5张图片

(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 '[email protected]' \
  -F 'raw.asset1.filename=sonarqube-community-branch-plugin-1.12.0'

持续集成交付CICD:通过API方式上传Nexus制品_第6张图片

(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'

持续集成交付CICD:通过API方式上传Nexus制品_第7张图片

(7)显示已上传成功

持续集成交付CICD:通过API方式上传Nexus制品_第8张图片

二、问题

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 "[email protected];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 "[email protected];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 "[email protected];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 "[email protected];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 "[email protected];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,ci/cd,运维,运维开发)