diff --git a/scripts/src/hwlab-node-web-sentinel-cicd.ts b/scripts/src/hwlab-node-web-sentinel-cicd.ts index 3e932d4d..7209da7d 100644 --- a/scripts/src/hwlab-node-web-sentinel-cicd.ts +++ b/scripts/src/hwlab-node-web-sentinel-cicd.ts @@ -2092,7 +2092,7 @@ function sentinelSourceMirrorSshSetupShellLines(state: SentinelCicdState): strin } function runSentinelPublishJob(state: SentinelCicdState, publishGitops: boolean, timeoutSeconds: number): SentinelRemoteJobResult { - const pipelineRunName = `${stringAt(state.cicd, "builder.jobPrefix")}-${Date.now().toString(36)}`.replace(/[^a-z0-9-]/giu, "-").toLowerCase().slice(0, 63); + const pipelineRunName = sentinelPipelineRunName(state); const manifest = sentinelPublishPipelineRunManifest(state, pipelineRunName, publishGitops); const namespace = stringAt(state.cicd, "builder.namespace"); sentinelProgressEvent("sentinel.publish.progress", { phase: "create-pipelinerun", status: "submitting", pipelineRun: pipelineRunName, publishGitops, sourceCommit: state.sourceHead.commit, node: state.spec.nodeId, lane: state.spec.lane }); @@ -2626,12 +2626,19 @@ function createTektonPipelineRunScript(namespace: string, manifest: Record/dev/null 2>&1 || true", - "kubectl -n \"$namespace\" delete taskrun -l tekton.dev/pipelineRun=\"$pipeline_run\" --ignore-not-found=true --wait=false >/dev/null 2>&1 || true", - "kubectl -n \"$namespace\" delete pod -l tekton.dev/pipelineRun=\"$pipeline_run\" --ignore-not-found=true --wait=false >/dev/null 2>&1 || true", "tmp=$(mktemp)", `cat >"$tmp" <<'YAML'\n${yaml}YAML`, - "kubectl apply -f \"$tmp\"", + "if kubectl -n \"$namespace\" get pipelinerun \"$pipeline_run\" >/dev/null 2>&1; then", + " printf '%s\\n' \"sentinel publish PipelineRun already exists; reusing $pipeline_run\"", + " exit 0", + "fi", + "if ! kubectl create -f \"$tmp\"; then", + " if kubectl -n \"$namespace\" get pipelinerun \"$pipeline_run\" >/dev/null 2>&1; then", + " printf '%s\\n' \"sentinel publish PipelineRun appeared concurrently; reusing $pipeline_run\"", + " exit 0", + " fi", + " exit 1", + "fi", ].join("\n"); }