Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI #1

Closed
030 opened this issue Apr 24, 2019 · 2 comments
Closed

CI #1

030 opened this issue Apr 24, 2019 · 2 comments

Comments

@030
Copy link
Owner

030 commented Apr 24, 2019

https://chadmayfield.com/2018/09/01/pulling-artifacts-from-nexus-in-less-than-25-lines-of-bash/

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

or

https://www.waltercedric.com/index.php/development/129-java/framework/maven-build-system/2302-fetching-artifact-programmatically-through-rest-api-in-nexus-3-x

#!/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
@030
Copy link
Owner Author

030 commented Apr 25, 2019

In order to get all artifacts:

curl -u user:pass -X GET "https://nexus-host/service/rest/v1/assets?repository=releases&continuationToken=some-token" -H  "accept: application/json"

All downloadUrls

./nexus-download.sh | jq .items[].downloadUrl

DownloadUrls for individual artifact

/service/rest/v1/search/assets?repository=releases&name=name&version=version" -H  "accept: application/json" | jq .items[].downloadUrl

The following returns more than 10.

v1/search/assets

Upload artifacts

curl -u admin:admin123 -X POST "http://localhost:8081/service/rest/v1/components?repository=maven-releases" -H  "accept: application/json" -H  "Content-Type: multipart/form-data" -F "maven2.asset1=@/home/user/.gradle/caches/modules-2/files-2.1/org.springframework/spring-beans/5.1.6.RELEASE/a7c61020fb4f4e937ed5cfef0d0d08c55d24cbb6/spring-beans-5.1.6.RELEASE.pom" -F "maven2.asset1.extension=pom" -F "maven2.asset2=@/home/user/.gradle/caches/modules-2/files-2.1/org.springframework/spring-beans/5.1.6.RELEASE/90d2f4bf7eced108de0b5bf617abb2b13a6206a3/spring-beans-5.1.6.RELEASE.jar" -F "maven2.asset2.extension=jar"

Find all artifacts downloadUrls

curl -X GET "http://localhost:8081/service/rest/v1/search/assets?repository=maven-releases" -H  "accept: application/json"

Download all artifacts

curl -u admin:admin123 -L -X GET "http://localhost:8081/service/rest/v1/search/assets/download?repository=maven-releases&name=spring-beans&version=5.1.6.RELEASE&maven.extension=jar" -H  "accept: application/json" -o spring-beans-5.1.6.jar

@030 030 changed the title Download all artifacts Upload and download all artifacts Apr 25, 2019
030 added a commit that referenced this issue Apr 26, 2019
030 added a commit that referenced this issue Apr 26, 2019
030 added a commit that referenced this issue Apr 26, 2019
@030 030 changed the title Upload and download all artifacts CI Apr 27, 2019
030 added a commit that referenced this issue Apr 27, 2019
030 added a commit that referenced this issue Apr 27, 2019
@030
Copy link
Owner Author

030 commented Apr 27, 2019

The job exceeded the maximum log length, and has been terminated.

030 added a commit that referenced this issue Apr 27, 2019
030 added a commit that referenced this issue Apr 27, 2019
030 added a commit that referenced this issue Apr 27, 2019
030 added a commit that referenced this issue Apr 27, 2019
@030 030 closed this as completed Apr 27, 2019
@030 030 reopened this Mar 4, 2020
@030 030 closed this as completed Mar 4, 2020
030 added a commit that referenced this issue Mar 29, 2020
030 added a commit that referenced this issue Mar 29, 2020
030 added a commit that referenced this issue Mar 29, 2020
030 added a commit that referenced this issue Mar 29, 2020
030 added a commit that referenced this issue Mar 29, 2020
030 added a commit that referenced this issue Mar 29, 2020
030 added a commit that referenced this issue Mar 29, 2020
030 added a commit that referenced this issue Mar 29, 2020
030 added a commit that referenced this issue Mar 29, 2020
030 added a commit that referenced this issue Oct 1, 2022
030 added a commit that referenced this issue Oct 1, 2022
030 added a commit that referenced this issue Oct 1, 2022
030 added a commit that referenced this issue Oct 1, 2022
030 added a commit that referenced this issue Oct 1, 2022
030 added a commit that referenced this issue Oct 1, 2022
030 added a commit that referenced this issue Oct 1, 2022
030 added a commit that referenced this issue Oct 1, 2022
030 added a commit that referenced this issue Oct 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant