download - 在 vsts 发布定义中从 nexus 下载构建工件
问题描述
我有 Maven 构建的构建定义。构建后,我使用 nexus 工件上传插件将工件上传到 nexus 存储库。
从发布定义中,有什么方法可以从我的部署中下载来自 nexus 的工件?
解决方案
如果您使用的是 nexus 2.x,则可以使用 REST API 从 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 repo 下载工件:
选项 1:使用 maven 命令
mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.1:copy -Dartifact=log4j:log4j:1.2.17:jar -DoutputDirectory=./
选项 2:使用 wget 和 bash 脚本下载:
#!/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
推荐阅读
- racket - 用一系列已知元素填充列表
- cassandra - Jupyter notebook 正在 linux 上查询 cassandra,输出有时间戳 utc 而不是 cst
- c - 如何在 C 的命令行参数中指定此类目录名称的目录中创建文件
- visual-studio - 两个碰撞器正在碰撞,但 OnColliderEnter2d 函数也没有被执行
- google-bigquery - 从简单的 STRUCT 数据类型中提取值
- r - R mac catalina tabulizer 失败,出现 java 运行时缺失错误,但已安装 java
- arrays - 处理结构内的可变字符串数组 (C)
- python - 如何从欧拉角计算“旋转流动性”的量度?
- python - 使用 numpy.polynomial.legendre 时,如何获得将输入转换为勒让德多项式的参数的函数?
- ruby-on-rails - 将枚举与管理集成的正确方法是什么?