如何使用Jenkins从nexus获取jar文件?

时间:2017-09-27 08:57:35

标签: java python maven jenkins jar

我有一个包含3个参数的Jenkins作业:ARTIFACT_ID,GROUP_ID和APP_VERSION。我想使用这3个参数从Nexus下载任何特定的jar文件。

请注意,Jenkins配置中提供了Nexus URL,因此它会自动知道从哪里查找。

你知道怎么做!!

例如,对于python应用程序,我使用pip download --no-deps ARTIFACT_ID==APP_VERSION,它可以正常工作。

1 个答案:

答案 0 :(得分:2)

您可以使用curl和xmllint的shell脚本访问Nexus api并下载工件。

以下是我如何从Nexus中检索工件的示例:

NEXUS_BASE_URL=https://nexus.example.com
REPOSITORY="reponame"
GROUP_ID="groupid"
ARTIFACT_ID="artifact_id"
LOCAL_FILE="destination.jar"

NEXUS_RESOLVE_URL="${NEXUS_BASE_URL}artifact/maven/resolve?g=${GROUP_ID}a=${ARTIFACT_ID}&r=${REPOSITORY}&v=${VERSION}"
REPOSITORY_LOCAL_PATH=`curl -s "${NEXUS_RESOLVE_URL}" | xmllint --xpath "//artifact-resolution/data/repositoryPath/text()" -`
ARTIFACT_DOWNLOAD_URL="${NEXUS_BASE_URL}repositories/${REPOSITORY}/content${REPOSITORY_LOCAL_PATH}"
curl -o "${LOCAL_FILE}" "${ARTIFACT_DOWNLOAD_URL}"

有关解决atrifacts的更多信息可以在nexus api参考文献中找到 https://repository.sonatype.org/nexus-restlet1x-plugin/default/docs/path__artifact_maven_resolve.html

相关问题