首页 > 解决方案 > 如何获取 Nexus 存储库的给定命名空间中的工件名称列表

问题描述

我只需要获取 nexus 存储库中给定名称空间下的工件名称。

用于上传的 Nexus URL: http: //nexus.it.test.com :8080/nexus/repository/rawcentral/com.test/

样本工件名称:release_dev_2018909.tar.gz

请帮助我使用确切的 shell 命令来获取所有工件名称的列表。TIA

标签: shelljenkinsrepositorynexus

解决方案


上面的脚本可以帮助你

#!/bin/bash

url="http://fileserver/service/rest/beta/search/assets?repository=maven-releases&name=dot-files"

artifact=( $(curl -s -X GET --header 'Accept: application/json' \
    "$url" | grep -Po '"downloadUrl" : ".*?[^\\]*.(zip.sha1|zip)",' | \
    awk -F '"' '{print $4}' | sort -Vr | head -n2) )

((${#artifact[@]})) || echo "ERROR! No artifacts found at provided url!"

for i in "${artifact[@]}"; do
    if [[ $i =~ (sha1) ]]; then
        checksum=$(curl -s "$i" | awk '{print $1}')
    else
        file="$(echo "$i" | awk -F "/" '{print $NF}')"
        curl -sO "$i" || { echo "ERROR: Download failed!"; exit 1; }

        if [ "$(sha1sum "$file" | awk '{print $1}')" != "$checksum" ]; then
            echo "ERROR: Checksum validation on $file failed!"; exit 1;
        else
            printf "Downloaded : %s\nChecksum   : %s\n" "$file" "$checksum"
        fi
    fi
done
#EOF

推荐阅读