CI流水线中制品库集成 maven编译过后包上传
使用本地仓库
现在去配置仓库的认证信息才能去上传,这个认证信息在maven里面去配置的
我们需要在nexus中创建一个新的仓库maven-hostd,同时我们需要在maven的配置文件settings.xml中配置maven-hostd认证。如下:
[root@jenkins-master ~]# vim /usr/local/apache-maven-3.8.1/conf/settings.xml
<server>
<id>maven-hosted</id>
<username>admin</username>
<password>admin123</password>
</server>
注意使用mvn deploy 发布时,server.id == respository.id。
mvn deploy:deploy-file
-DgroupId=xxxxxx pom中的groupId
-DartifactId=xxxxxx pom中的artifactId
-Dversion=xxxxxx pom中的版本号version
-Dpackaging=xxxxxx pom中打包方式
-Dfile=xxxxxx 本地文件
-Durl=xxxxxx 仓库url
-DrepositoryId=xxxxxx 对应的是setting.xml(认证)
直接读取pom文件(方便),获取pom文件里面的信息上传
mvn deploy:deploy-file \
-DgeneratePom=false \
-DrepositoryId=maven-hosted \
-Durl=http://139.198.170.122:8081/repository/maven-hosted/ \
-DpomFile=pom.xml \
-Dfile=target/demo-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.987 s
[INFO] Finished at: 2021-06-16T17:33:52+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy-file (default-cli) on project demo: Failed to deploy artifacts: Could not transfer artifact com.example:demo:jar:0.0.1-20210616.093352-1 from/to maven-hosted (http://139.198.170.122:8081/repository/maven-hosted/): transfer failed for http://139.198.170.122:8081/repository/maven-hosted/com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-20210616.093352-1.jar, status: 400 Repository version policy: RELEASE does not allow version: 0.0.1-20210616.093352-1 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[root@jenkins-master devops-maven-service-master]# vim pom.xml
<version>0.0.1-SNAPSHOT</version>
将snapshit版本修改为release版本
<version>0.0.1</version>
[root@jenkins-master devops-maven-service-master]# mvn deploy:deploy-file \
> -DgeneratePom=false \
> -DrepositoryId=maven-hosted \
> -Durl=http://139.198.170.122:8081/repository/maven-hosted/ \
> -DpomFile=pom.xml \
> -Dfile=target/demo-0.0.1-SNAPSHOT.jarvim pom.xml ^C
[root@jenkins-master devops-maven-service-master]# ^C
[root@jenkins-master devops-maven-service-master]# ^C
[root@jenkins-master devops-maven-service-master]# vim pom.xml
[root@jenkins-master devops-maven-service-master]# mvn deploy:deploy-file \
> -DgeneratePom=false \
> -DrepositoryId=maven-hosted \
> -Durl=http://139.198.170.122:8081/repository/maven-hosted/ \
> -DpomFile=pom.xml \
> -Dfile=target/demo-0.0.1-SNAPSHOT.jar
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy-file (default-cli) @ demo ---
Uploading to maven-hosted: http://139.198.170.122:8081/repository/maven-hosted/com/example/demo/0.0.1/demo-0.0.1.jar
Uploaded to maven-hosted: http://139.198.170.122:8081/repository/maven-hosted/com/example/demo/0.0.1/demo-0.0.1.jar (17 MB at 439 kB/s)
Uploading to maven-hosted: http://139.198.170.122:8081/repository/maven-hosted/com/example/demo/0.0.1/demo-0.0.1.pom
Uploaded to maven-hosted: http://139.198.170.122:8081/repository/maven-hosted/com/example/demo/0.0.1/demo-0.0.1.pom (1.2 kB at 5.9 kB/s)
Downloading from maven-hosted: http://139.198.170.122:8081/repository/maven-hosted/com/example/demo/maven-metadata.xml
Uploading to maven-hosted: http://139.198.170.122:8081/repository/maven-hosted/com/example/demo/maven-metadata.xml
Uploaded to maven-hosted: http://139.198.170.122:8081/repository/maven-hosted/com/example/demo/maven-metadata.xml (295 B at 3.0 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 40.967 s
[INFO] Finished at: 2021-06-16T17:39:16+08:00
[INFO] ------------------------------------------------------------------------
自定义pom信息(灵活)
mvn deploy:deploy-file -Dmaven.test.skip=true \
-Dfile=target/demo-0.0.1-SNAPSHOT.jar \
-DgroupId=com.example \
-DartifactId=demo \
-Dversion=1.1.1 \
-Dpackaging=jar \
-DrepositoryId=maven-hosted \
-Durl=http://139.198.170.122:8081/repository/maven-hosted/
这就是包的上传方式,比如你有npm,gradle这些。
目录 返回
首页