feat: new client, store and docs
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env bash
|
||||
# Agrega un nodo permanente (SCO) a data/jenkins/jenkins.yaml.
|
||||
#
|
||||
# Uso:
|
||||
# create-node.sh --cliente <cliente> --tienda <tienda> --numero <numero>
|
||||
#
|
||||
# Ejemplo:
|
||||
# create-node.sh --cliente ralph --tienda yabucoa --numero 8
|
||||
# -> nodo "ralph-yabucoa-sco008", label "sco ralph yabucoa"
|
||||
#
|
||||
# Por default valida que el cliente ya esté dado de alta (que exista
|
||||
# Jenkinsfile.<cliente>) y que la tienda esté en su dropdown de TIENDA.
|
||||
# --skip-checks salta ambas validaciones (lo usa create-client.sh al dar
|
||||
# de alta un cliente nuevo, cuando el Jenkinsfile todavía no existe).
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
JENKINS_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
JENKINS_YAML="$JENKINS_DIR/jenkins.yaml"
|
||||
PIPELINES_DIR="$JENKINS_DIR/pipelines"
|
||||
|
||||
cliente=""
|
||||
tienda=""
|
||||
numero=""
|
||||
skip_checks=false
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--cliente) cliente="$2"; shift 2 ;;
|
||||
--tienda) tienda="$2"; shift 2 ;;
|
||||
--numero) numero="$2"; shift 2 ;;
|
||||
--skip-checks) skip_checks=true; shift ;;
|
||||
*) echo "Argumento desconocido: $1" >&2; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
command -v yq >/dev/null 2>&1 || {
|
||||
echo "yq no está instalado. Instalalo (ej. 'apt install yq' o ver https://github.com/mikefarah/yq#install)." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[[ -n "$cliente" && -n "$tienda" && -n "$numero" ]] || {
|
||||
echo "Uso: $0 --cliente <cliente> --tienda <tienda> --numero <numero>" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[[ "$cliente" =~ ^[a-z0-9-]+$ ]] || { echo "cliente inválido: '$cliente' (solo minúsculas, números y guiones)" >&2; exit 1; }
|
||||
[[ "$tienda" =~ ^[a-z0-9-]+$ ]] || { echo "tienda inválida: '$tienda' (solo minúsculas, números y guiones)" >&2; exit 1; }
|
||||
[[ "$numero" =~ ^[0-9]+$ ]] || { echo "numero inválido: '$numero' (solo dígitos)" >&2; exit 1; }
|
||||
|
||||
numero_padded=$(printf '%03d' "$((10#$numero))")
|
||||
node_name="${cliente}-${tienda}-sco${numero_padded}"
|
||||
node_label="sco ${cliente} ${tienda}"
|
||||
|
||||
[[ -f "$JENKINS_YAML" ]] || { echo "No se encontró $JENKINS_YAML" >&2; exit 1; }
|
||||
|
||||
if [[ "$skip_checks" == false ]]; then
|
||||
jenkinsfile="$PIPELINES_DIR/Jenkinsfile.${cliente}"
|
||||
[[ -f "$jenkinsfile" ]] || {
|
||||
echo "El cliente '$cliente' no está dado de alta (no existe $jenkinsfile)." >&2
|
||||
echo "Usá create-client.sh para darlo de alta primero." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
choices_line=$(grep -m1 "choices:" "$jenkinsfile" || true)
|
||||
if [[ -n "$choices_line" ]] && ! grep -oE "'[a-z0-9-]+'" <<< "$choices_line" | tr -d "'" | grep -qx "$tienda"; then
|
||||
echo "La tienda '$tienda' no está en el dropdown de $jenkinsfile" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if yq eval ".jenkins.nodes[].permanent.name" "$JENKINS_YAML" | grep -qx "$node_name"; then
|
||||
echo "El nodo '$node_name' ya existe en $JENKINS_YAML" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NODE_NAME="$node_name" NODE_LABEL="$node_label" yq eval -i '
|
||||
.jenkins.nodes += [{
|
||||
"permanent": {
|
||||
"name": strenv(NODE_NAME),
|
||||
"labelString": strenv(NODE_LABEL),
|
||||
"remoteFS": "/opt/jenkins-agent",
|
||||
"numExecutors": 1,
|
||||
"retentionStrategy": "always",
|
||||
"launcher": {
|
||||
"inbound": {
|
||||
"webSocket": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
' "$JENKINS_YAML"
|
||||
|
||||
echo "Nodo creado: $node_name (label: $node_label)"
|
||||
if [[ "$skip_checks" == false ]]; then
|
||||
echo ""
|
||||
echo "Revisá en jenkins.yaml > jenkins > nodes"
|
||||
echo "Aplicá con: docker compose up -d --build"
|
||||
fi
|
||||
Reference in New Issue
Block a user