在vsts版本定义中从nexus下载构建构件 [英] build artifacts download from nexus in vsts release definition
问题描述
我有Maven构建的构建定义.构建后,我使用nexus工件上传插件将工件上传到nexus存储库.
I have the build definition which does Maven build. after the build I upload artifacts to nexus repository using nexus artifacts upload plugin.
从发行版定义中,有什么方法可以从nexus下载工件以进行部署?
From release definition is there any way to download the artifacts from nexus for my deployment?
推荐答案
如果您使用的是nexus 2.x ,则可以使用REST API从nexus存储库下载工件:
If you are using nexus 2.x, you can use the REST API to download artifacts from nexus repo:
wget "http://local:8081/service/local/artifact/maven/redirect?g=com.mycompany&a=my-app&v=LATEST" --content-disposition
或
curl --insecure "https://local:8081/service/local/artifact/maven/content?r=public&g=log4j&a=log4j&v=1.2.17&p=jar&c=" > log4j.ja
如果您使用的是nexus 3.x ,则可以使用以下方法从nexus存储库下载工件:
If you are using nexus 3.x, you can use below ways to download artifacts from nexus repo:
-
选项1:使用maven命令
Option 1: Use maven command
mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.1:copy -Dartifact=log4j:log4j:1.2.17:jar -DoutputDirectory=./
选项2:将wget与bash脚本一起使用进行下载:
Option 2: use wget with bash script to download:
#!/bin/sh
repo="https://nexus.url.com"
groupId=$1
artifactId=$2
version=$3
# optional
classifier=$4
type=$5
if [[ $type == "" ]]; then
type="jar"
fi
if [[ $classifier != "" ]]; then
classifier="-${classifier}"
fi
groupIdUrl="${groupId//.//}"
filename="${artifactId}-${version}${classifier}.${type}"
if [[ ${version} == *"SNAPSHOT"* ]]; then repo_type="snapshots"; else repo_type="releases"; fi
if [[ $repo_type == "releases" ]]
then
wget --no-check-certificate "${repo}/repository/releases/${groupIdUrl}/${artifactId}/${version}/${artifactId}-${version}${classifier}.${type}" -O ${filename} -k
else
versionTimestamped=$(wget -q -O- --no-check-certificate "${repo}/repository/snapshots/${groupIdUrl}/${artifactId}/${version}/maven-metadata.xml" | grep -m 1 \<value\> | sed -e 's/<value>\(.*\)<\/value>/\1/' | sed -e 's/ //g')
wget --no-check-certificate "${repo}/repository/snapshots/${groupIdUrl}/${artifactId}/${version}/${artifactId}-${versionTimestamped}${classifier}.${type}" -O ${filename}
fi
´´´
usage
script.sh groupid artifactid version classifier type
ex:
script.sh log4j log4j 4.2.18 sources zip
script.sh log4j log4j 4.2.19 -> get jar as default
script.sh log4j log4j 4.2.19-SNAPSHOT -> get jar as default
更多详细信息,您可以参考获取Nexus 2/a 通过REST/API以编程方式生成工件.
More details, you can refer Fetching artifact programmatically through REST/API fro Nexus2/3.
这篇关于在vsts版本定义中从nexus下载构建构件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!