如何获取给定名称空间的Nexus存储库中的工件名称列表

时间:2019-03-29 09:53:22

标签: shell jenkins repository nexus

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

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

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

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

1 个答案:

答案 0 :(得分:0)

以上脚本可以为您提供帮助

#!/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