Files
rme-jenkins/jenkins_publisher.sh
T
2026-08-19 12:13:32 +02:00

63 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Upload produced DEB packages to the internal artifact repository and emit two
# helper files for the Jenkinsfile to consume (named per project + OS version):
# ${WORKSPACE}/url-${PROJECT}-${OS_VERSION}.txt — browseable URL of the uploaded folder
# ${WORKSPACE}/tdsversion-${PROJECT}-${OS_VERSION}.txt — full version string (LTS-build)
#
# Required environment (set by the Jenkinsfile / withCredentials):
# PROJECT LTS flavor: ahtc | guez
# OS_VERSION Ubuntu base version, e.g. 26.04
# LTS_VERSION Major.minor LTS version, e.g. 1.0
# BUILD_NUMBER Jenkins build number (release component of the artifact name)
# WORKSPACE Jenkins workspace path
# ARTIFACTREPO Base URL of the internal repo (no trailing slash)
# ARTIFACTFOLDER Subfolder under cts-debs/ (project name, e.g. qatar)
# CURL_CRED user:password for the upload (Jenkins credential)
#
set -eo pipefail
: "${PROJECT:?PROJECT must be set}"
: "${OS_VERSION:?OS_VERSION must be set}"
: "${LTS_VERSION:?LTS_VERSION must be set}"
: "${BUILD_NUMBER:?BUILD_NUMBER must be set}"
: "${WORKSPACE:?WORKSPACE must be set}"
: "${ARTIFACTREPO:?ARTIFACTREPO must be set}"
: "${ARTIFACTFOLDER:?ARTIFACTFOLDER must be set}"
: "${CURL_CRED:?CURL_CRED must be set}"
tds_folder_name="${PROJECT}-TDS-${LTS_VERSION}-${BUILD_NUMBER}"
tds_folder_path="${WORKSPACE}/rpms/${PROJECT}/${OS_VERSION}"
tds_artifact_store="${ARTIFACTREPO}/repository/cts-debs/${ARTIFACTFOLDER}/${OS_VERSION}/${tds_folder_name}"
if [ ! -d "${tds_folder_path}/${tds_folder_name}" ]; then
echo "ERROR: expected RPM folder not found: ${tds_folder_path}/${tds_folder_name}" >&2
exit 1
fi
shopt -s nullglob
uploaded=0
for file in "${tds_folder_path}/${tds_folder_name}"/*; do
[ -f "${file}" ] || continue
name=$(basename "${file}")
echo "Uploading: ${name}"
curl --fail --silent --show-error \
--user "${CURL_CRED}" \
--upload-file "${file}" \
"${tds_artifact_store}/${name}"
uploaded=$((uploaded + 1))
done
if [ "${uploaded}" -eq 0 ]; then
echo "ERROR: no files uploaded from ${tds_folder_path}/${tds_folder_name}" >&2
exit 1
fi
echo "Uploaded ${uploaded} file(s) to ${tds_artifact_store}/"
# Per-(project, OS) filenames so concurrent publish stages don't clobber each
# other's helper files; the Jenkinsfile reads back the matching names.
echo "${ARTIFACTREPO}/service/rest/repository/browse/cts-debs/${ARTIFACTFOLDER}/${OS_VERSION}/${tds_folder_name}/" > "${WORKSPACE}/url-${PROJECT}-${OS_VERSION}.txt"
echo "${LTS_VERSION}-${BUILD_NUMBER}" > "${WORKSPACE}/tdsversion-${PROJECT}-${OS_VERSION}.txt"