119 lines
4.0 KiB
Groovy
119 lines
4.0 KiB
Groovy
// Add the Gitea webhook configured for this Jenkins installation.
|
|
|
|
pipeline {
|
|
agent { label 'rust_nodocker' }
|
|
|
|
options {
|
|
disableConcurrentBuilds()
|
|
skipDefaultCheckout(true)
|
|
}
|
|
|
|
environment {
|
|
ASSET_SOURCE_DIR = 'shared-tasks'
|
|
ASSET_PUBLISH_ROOT = '/mnt/assets/agent-tasks'
|
|
}
|
|
|
|
stages {
|
|
stage('Checkout') {
|
|
steps {
|
|
deleteDir()
|
|
checkout scm
|
|
}
|
|
}
|
|
|
|
stage('Discover publishable tasks') {
|
|
steps {
|
|
sh '''
|
|
set -eu
|
|
|
|
if [ ! -e "${ASSET_SOURCE_DIR}" ]; then
|
|
echo "No ${ASSET_SOURCE_DIR}/ directory; nothing is marked for publication."
|
|
exit 0
|
|
fi
|
|
|
|
test -d "${ASSET_SOURCE_DIR}" && test ! -L "${ASSET_SOURCE_DIR}" || {
|
|
echo "ERROR: ${ASSET_SOURCE_DIR} must be a real directory." >&2
|
|
exit 1
|
|
}
|
|
|
|
invalid_type=$(find "${ASSET_SOURCE_DIR}" ! -type d ! -type f -print -quit)
|
|
test -z "${invalid_type}" || {
|
|
echo "ERROR: publishable assets must be regular files: ${invalid_type}" >&2
|
|
exit 1
|
|
}
|
|
|
|
task_count=0
|
|
for task in "${ASSET_SOURCE_DIR}"/*.task.md; do
|
|
test -e "${task}" || continue
|
|
test -f "${task}" && test ! -L "${task}" && test -s "${task}" || {
|
|
echo "ERROR: task must be a nonempty regular file: ${task}" >&2
|
|
exit 1
|
|
}
|
|
task_count=$((task_count + 1))
|
|
done
|
|
|
|
unexpected=$(find "${ASSET_SOURCE_DIR}" -mindepth 1 \
|
|
\( ! -type f -o ! -name '*.task.md' \) -print -quit)
|
|
test -z "${unexpected}" || {
|
|
echo "ERROR: unexpected file in ${ASSET_SOURCE_DIR}: ${unexpected}" >&2
|
|
exit 1
|
|
}
|
|
|
|
if [ "${task_count}" -eq 0 ]; then
|
|
echo "No shared task files are marked for publication."
|
|
else
|
|
echo "Validated ${task_count} shared task files for publication."
|
|
fi
|
|
'''
|
|
}
|
|
}
|
|
|
|
stage('Publish assets') {
|
|
when {
|
|
branch 'main'
|
|
}
|
|
steps {
|
|
sh '''
|
|
set -eu
|
|
|
|
if [ ! -d "${ASSET_SOURCE_DIR}" ]; then
|
|
echo "Nothing is marked for publication."
|
|
exit 0
|
|
fi
|
|
|
|
set -- "${ASSET_SOURCE_DIR}"/*.task.md
|
|
if [ ! -e "$1" ]; then
|
|
echo "Nothing is marked for publication."
|
|
exit 0
|
|
fi
|
|
|
|
case "${ASSET_PUBLISH_ROOT}" in
|
|
/*) ;;
|
|
*)
|
|
echo "ERROR: ASSET_PUBLISH_ROOT must be absolute." >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
mkdir -p "${ASSET_PUBLISH_ROOT}"
|
|
chmod 0755 "${ASSET_PUBLISH_ROOT}"
|
|
|
|
for source in "$@"; do
|
|
name=${source##*/}
|
|
destination="${ASSET_PUBLISH_ROOT}/${name}"
|
|
temporary="${destination}.tmp-${BUILD_NUMBER}-$$"
|
|
|
|
trap 'rm -f "${temporary}"' 0 1 2 3 15
|
|
cp "${source}" "${temporary}"
|
|
chmod 0644 "${temporary}"
|
|
mv "${temporary}" "${destination}"
|
|
trap - 0 1 2 3 15
|
|
done
|
|
|
|
echo "Published task files below ${ASSET_PUBLISH_ROOT}."
|
|
'''
|
|
}
|
|
}
|
|
}
|
|
}
|