Skip to content

Instantly share code, notes, and snippets.

@nightspotlight
Created July 6, 2020 09:33
Show Gist options
  • Save nightspotlight/28efd7e9ce935763d8ebc8d41f8d919a to your computer and use it in GitHub Desktop.
Save nightspotlight/28efd7e9ce935763d8ebc8d41f8d919a to your computer and use it in GitHub Desktop.
Upload multiple RPM files to a Maven repository in Sonatype Nexus Repository Manager 2
#!/usr/bin/env bash
for f in *.rpm; do
rpminfo="$(rpm -qp --queryformat "%{NAME} %{VERSION}-%{RELEASE} %{ARCH}\n" "${f}" 2>/dev/null)"
group="org.centos-7.rpm"
artifact="$(echo "${rpminfo}" | cut -d ' ' -f 1)"
version="$(echo "${rpminfo}" | cut -d ' ' -f 2)"
classifier="$(echo "${rpminfo}" | cut -d ' ' -f 3)"
curl -fsSL \
-u nexus_user:nexus_password \
-F r=mvn-repository \
-F hasPom=false \
-F g="${group}" \
-F a="${artifact}" \
-F v="${version}" \
-F c="${classifier}" \
-F e=rpm \
-F p=rpm \
-F file=@"${f}" \
"https://nexus2.example.com:8443/service/local/artifact/maven/content"
cat << EOF
<dependency>
<groupId>${group}</groupId>
<artifactId>${artifact}</artifactId>
<version>${version}</version>
<classifier>${classifier}</classifier>
<type>rpm</type>
</dependency>
EOF
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment