Skip to content
295 changes: 209 additions & 86 deletions .github/workflows/ti_platforms_jenkins.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Build TI platforms (Jenkins)

# Starts the zsod_utils_twister_build Jenkins job for each platform on the
# pull request and waits for it. Same build-only twister run as
# Starts the zsod_utils_twister_build_all Jenkins job for the pull request and
# waits for it. That master job builds every TI platform in parallel (one
# zsod_utils_twister_build worker per platform). Same build-only twister run as
# ti_platforms_build.yaml, on the internal Jenkins nodes. The result comes back
# as one check per platform and one comment on the pull request.
# as one check and one comment on the pull request. Cancelling this run (a new
# push) stops the master, and the master stops its workers.
#
# The EPSW_JENKINS_* secrets are for jenkins-epsw.itg.ti.com, where this job
# lives. The JENKINS_* secrets of zephyr-board-ci.yml are for another Jenkins.
Expand All @@ -27,43 +29,28 @@ concurrency:
cancel-in-progress: true

env:
JENKINS_JOB: zsod_utils_twister_build
JENKINS_JOB: zsod_utils_twister_build_all

jobs:
build:
name: Jenkins build (${{ matrix.platform }})
name: Jenkins builds of the TI platforms
runs-on: [self-hosted, Linux, X64] # the self-hosted runner that can reach Jenkins
timeout-minutes: 720
strategy:
fail-fast: false
matrix:
platform:
- lp_am13e230
- lp_mspm0g3507
- lp_mspm0g3519
- lp_mspm0l2228
- lp_mspm33c321a
- am62l_evm/am62l3/a53
permissions:
contents: read
pull-requests: write
env:
SECRET_URL: ${{ secrets.EPSW_JENKINS_URL }}
JENKINS_USER: ${{ secrets.EPSW_JENKINS_USER }}
JENKINS_TOKEN: ${{ secrets.EPSW_JENKINS_TOKEN }}
PLATFORM: ${{ matrix.platform }}
PR_NUMBER: ${{ github.event.pull_request.number }}
steps:
- name: Run the Jenkins build and wait for it
- name: Start the Jenkins master job and wait for it
shell: bash
run: |
set -uo pipefail
cd "$RUNNER_TEMP"

# leave an outcome behind for the comment job, whatever happens
RESULT="ERROR"
BUILD_URL=""
finish() {
printf '%s\n%s\n' "$RESULT" "$BUILD_URL" > "$RUNNER_TEMP/result.txt"
}
trap finish EXIT
: > "$RUNNER_TEMP/build-url"

[[ -n "${SECRET_URL:-}" ]] || { echo "ERROR: the EPSW_JENKINS_URL secret is not set"; exit 1; }
[[ "$PR_NUMBER" =~ ^[0-9]+$ ]] || { echo "ERROR: invalid PR number"; exit 1; }
Expand All @@ -74,132 +61,268 @@ jobs:
# Jenkins is internal and the site proxy intercepts its TLS, so these
# calls bypass the proxy. Credentials go in a file, not on the
# command line (visible in the process list of the shared host).
JOPTS="--noproxy $H"
NETRC=$(mktemp); chmod 600 "$NETRC"
trap 'rm -f "$NETRC"' EXIT
printf 'machine %s login %s password %s\n' "$H" "$JENKINS_USER" "$JENKINS_TOKEN" > "$NETRC"
JOPTS="$JOPTS --netrc-file $NETRC"
trap 'rm -f "$NETRC"; finish' EXIT
JOPTS="--noproxy $H --netrc-file $NETRC"

# the CSRF crumb is tied to the session, so crumb and build share a cookie jar
jar=$(mktemp)
jar=$(mktemp); hdrs=$(mktemp)
json=$(curl -sf $JOPTS -c "$jar" "${URL}/crumbIssuer/api/json" || true)
field=$(echo "$json" | jq -r '.crumbRequestField // empty' 2>/dev/null || true)
crumb=$(echo "$json" | jq -r '.crumb // empty' 2>/dev/null || true)
hdrs=$(mktemp)
code=$(curl -s $JOPTS -o /dev/null -D "$hdrs" -w '%{http_code}' -X POST -b "$jar" -c "$jar" \
${field:+-H "$field: $crumb"} --get \
--data-urlencode "PLATFORM=${PLATFORM}" --data-urlencode "PR_NUMBER=${PR_NUMBER}" \
${field:+-H "$field: $crumb"} --get --data-urlencode "PR_NUMBER=${PR_NUMBER}" \
"${URL}/job/${JENKINS_JOB}/buildWithParameters")
rm -f "$jar"
if [[ "$code" != "201" ]]; then
QUEUE=$(grep -i '^location:' "$hdrs" | tr -d '\r' | awk '{print $2}')
rm -f "$jar" "$hdrs"
if [[ "$code" != "201" || -z "$QUEUE" ]]; then
echo "ERROR: Jenkins refused the build request (HTTP $code). Check the credentials and Job/Build on ${JENKINS_JOB}."
exit 1
fi
QUEUE=$(grep -i '^location:' "$hdrs" | tr -d '\r' | awk '{print $2}')
echo "Queued: $QUEUE"
printf 'queue\t%s\n' "$QUEUE" > "$RUNNER_TEMP/build-url"

# queue item -> build url
BUILD_URL=""
for _ in $(seq 1 120); do
BUILD_URL=$(curl -sf $JOPTS "${QUEUE}api/json" | jq -r '.executable.url // empty') || BUILD_URL=""
[[ -n "$BUILD_URL" ]] && break
sleep 15
done
[[ -n "$BUILD_URL" ]] || { RESULT="TIMEOUT"; echo "ERROR: the build did not start within 30 minutes"; exit 1; }
echo "Jenkins build: $BUILD_URL"
# lets the cancel step stop this build
printf '%s' "$BUILD_URL" > "$RUNNER_TEMP/build-url"
echo "[Jenkins build](${BUILD_URL}console)" >> "$GITHUB_STEP_SUMMARY"
[[ -n "$BUILD_URL" ]] || { echo "ERROR: the build did not start within 30 minutes"; exit 1; }
echo "Jenkins master build: $BUILD_URL"
printf 'build\t%s\n' "$BUILD_URL" > "$RUNNER_TEMP/build-url"
echo "[Jenkins master build](${BUILD_URL}console)" >> "$GITHUB_STEP_SUMMARY"

# wait for it, 12 hours at most
RESULT="TIMEOUT"
for _ in $(seq 1 1440); do
b=$(curl -sf $JOPTS "${BUILD_URL}api/json?tree=building,result") || b=""
if [[ -n "$b" && "$(echo "$b" | jq -r .building)" == "false" ]]; then
RESULT=$(echo "$b" | jq -r '.result // "ERROR"')
echo "Jenkins result: $RESULT"
curl -sf $JOPTS "${BUILD_URL}consoleText" \
| grep -E 'configurations passed|ERROR +Build failure' | tail -20 || true
[[ "$RESULT" == "SUCCESS" ]]
exit
break
fi
sleep 30
done
RESULT="TIMEOUT"
echo "ERROR: the Jenkins build did not finish in 12 hours"
exit 1
echo "Jenkins master result: $RESULT"

# one PLATFORM_RESULT line per platform, printed by the master
curl -sf $JOPTS "${BUILD_URL}consoleText" | grep -o 'PLATFORM_RESULT: .*' | sort -u > "$RUNNER_TEMP/platforms.txt" || true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. A green check can show no platform results 🐞 Bug ≡ Correctness

The build step suppresses failures while fetching and extracting PLATFORM_RESULT lines, then
decides its status solely from the master build result. If the console request fails or contains no
matching lines while the master reports SUCCESS, the workflow passes without any platform results.
Agent Prompt
## Issue description
A successful master build can yield a passing check even when its platform results cannot be read or are absent.
## Fix Focus Areas
- .github/workflows/ti_platforms_jenkins.yaml[110-120]
## Recommended Fix
Fail the build step when console retrieval or parsing fails, and require one valid result for each expected platform before returning success.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

cat "$RUNNER_TEMP/platforms.txt"
printf '%s\n' "$RESULT" > "$RUNNER_TEMP/result.txt"
{
echo "### Jenkins builds: $RESULT"
echo '```'
sed 's/^PLATFORM_RESULT: //' "$RUNNER_TEMP/platforms.txt"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
[[ "$RESULT" == "SUCCESS" ]]

- name: Stop the Jenkins build when this run is cancelled
- name: Stop the Jenkins master when this run is cancelled
if: cancelled()
shell: bash
run: |
[[ -s "$RUNNER_TEMP/build-url" ]] || exit 0
BUILD_URL=$(cat "$RUNNER_TEMP/build-url")
KIND=$(cut -f1 "$RUNNER_TEMP/build-url"); TARGET=$(cut -f2 "$RUNNER_TEMP/build-url")
URL="${SECRET_URL%/}"; H="${URL#*://}"; H="${H%%/*}"; H="${H%%:*}"
NETRC=$(mktemp); chmod 600 "$NETRC"
trap 'rm -f "$NETRC"' EXIT
printf 'machine %s login %s password %s\n' "$H" "$JENKINS_USER" "$JENKINS_TOKEN" > "$NETRC"
JOPTS="--noproxy $H --netrc-file $NETRC"
jar=$(mktemp)
json=$(curl -sf --noproxy "$H" --netrc-file "$NETRC" -c "$jar" "${URL}/crumbIssuer/api/json" || true)
json=$(curl -sf $JOPTS -c "$jar" "${URL}/crumbIssuer/api/json" || true)
field=$(echo "$json" | jq -r '.crumbRequestField // empty' 2>/dev/null || true)
crumb=$(echo "$json" | jq -r '.crumb // empty' 2>/dev/null || true)
curl -s --noproxy "$H" --netrc-file "$NETRC" -o /dev/null -X POST -b "$jar" \
${field:+-H "$field: $crumb"} "${BUILD_URL}stop" && echo "Stopped ${BUILD_URL}"
if [[ "$KIND" == "build" ]]; then
# the master pipeline aborts the workers it started
curl -s $JOPTS -o /dev/null -X POST -b "$jar" ${field:+-H "$field: $crumb"} "${TARGET}stop" \
&& echo "Stopped the master: $TARGET"
else
ID=$(basename "${TARGET%/}")
curl -s $JOPTS -o /dev/null -X POST -b "$jar" ${field:+-H "$field: $crumb"} \
"${URL}/queue/cancelItem?id=${ID}" && echo "Removed the master from the queue"
Comment on lines +141 to +144

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

3. Cancellation can leave the master running 🐞 Bug ☼ Reliability

The cancellation step chooses queue cancellation from the saved queue record without checking
whether that item has become an executable build. If Jenkins starts the master after that record is
written but before it is replaced with the build URL, cancelling the GitHub run targets the queue
item rather than the running master.
Agent Prompt
## Issue description
A saved queue URL can refer to a master that has already started, so queue cancellation alone does not stop it.
## Fix Focus Areas
- .github/workflows/ti_platforms_jenkins.yaml[84-95]
- .github/workflows/ti_platforms_jenkins.yaml[127-145]
## Recommended Fix
When cancellation finds a queue record, query the item for its executable URL and stop that build if present; otherwise cancel the still-queued item.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment on lines +143 to +144

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

4. Failed queue cancellation appears successful 🐞 Bug ◔ Observability

The new queue-cancellation request uses curl -s without checking the HTTP response before printing
its success message. If Jenkins rejects the request or the item cannot be cancelled, the workflow
can say it removed the master while Jenkins has not accepted the cancellation.
Agent Prompt
## Issue description
The new queue-cancellation path prints success for Jenkins HTTP error responses.
## Fix Focus Areas
- .github/workflows/ti_platforms_jenkins.yaml[141-145]
## Recommended Fix
Use a failing HTTP request or explicitly inspect the response status, and print success only after Jenkins accepts the cancellation; surface failures in the workflow log.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

fi
rm -f "$jar"

- name: Save the result for the comment
- name: Collect the twister log of each platform
id: prep
if: always()
shell: bash
env:
ATTEMPT: ${{ github.run_attempt }}
run: |
mkdir -p "$RUNNER_TEMP/out"
{ echo "$PLATFORM"; cat "$RUNNER_TEMP/result.txt" 2>/dev/null || printf 'ERROR\n\n'; } \
> "$RUNNER_TEMP/out/result.txt"
echo "ARTIFACT=result-${PLATFORM//\//_}" >> "$GITHUB_ENV"
set -uo pipefail
mkdir -p "$RUNNER_TEMP/twister-logs"
[[ -s "$RUNNER_TEMP/platforms.txt" && -s "$RUNNER_TEMP/build-url" ]] || exit 0
[[ -n "${SECRET_URL:-}" ]] || exit 0
URL="${SECRET_URL%/}"; H="${URL#*://}"; H="${H%%/*}"; H="${H%%:*}"
NETRC=$(mktemp); chmod 600 "$NETRC"
trap 'rm -f "$NETRC"' EXIT
printf 'machine %s login %s password %s\n' "$H" "$JENKINS_USER" "$JENKINS_TOKEN" > "$NETRC"
JOPTS="--noproxy $H --netrc-file $NETRC"

- name: Upload the result
if: always()
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
MASTER=$(cut -f2 "$RUNNER_TEMP/build-url"); MASTER="${MASTER%/}"
MNUM="${MASTER##*/}"
n=0
while read -r _ P R B; do
[[ -n "${P:-}" && -n "${B:-}" ]] || continue
B="${B%/}/"
# only take files of a build that this master started
cause=$(curl -sf $JOPTS "${B}api/json?tree=actions%5Bcauses%5BupstreamProject,upstreamBuild%5D%5D" \
| jq -r '[.actions[]?.causes[]? | select(.upstreamProject != null) | "\(.upstreamProject)#\(.upstreamBuild)"] | first // empty') || cause=""
if [[ "$cause" != "${JENKINS_JOB}#${MNUM}" ]]; then
echo "Skip $P: the build was not started by this master ($cause)"; continue
fi
safe="${P//\//_}"
f="pr${PR_NUMBER}-${ATTEMPT}-${safe}-twister.log"
curl -sf $JOPTS -o "$RUNNER_TEMP/twister-logs/$f" "${B}artifact/artifacts/logs/twister_build.log" \
|| { echo "No twister log for $P"; rm -f "$RUNNER_TEMP/twister-logs/$f"; continue; }
n=$((n+1))
if [[ $n -le 8 ]]; then
echo "board$n=$P" >> "$GITHUB_OUTPUT"
echo "file$n=$RUNNER_TEMP/twister-logs/$f" >> "$GITHUB_OUTPUT"
fi
done < "$RUNNER_TEMP/platforms.txt"
echo "Collected $n twister logs"
ls -l "$RUNNER_TEMP/twister-logs"

- name: Twister logs of all platforms
id: logs
if: always() && steps.prep.outputs.file1 != ''
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: ${{ env.ARTIFACT }}
path: ${{ runner.temp }}/out/result.txt

comment:
name: Comment the Jenkins results on the pull request
needs: build
if: always() && needs.build.result != 'skipped'
runs-on: ubuntu-24.04
permissions:
pull-requests: write
steps:
- name: Download the results
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
name: twister-logs-pr${{ github.event.pull_request.number }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/twister-logs
retention-days: 14

- name: Twister log 1
id: log1
if: always() && steps.prep.outputs.file1 != ''
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
path: ${{ steps.prep.outputs.file1 }}
archive: false
retention-days: 14

- name: Twister log 2
id: log2
if: always() && steps.prep.outputs.file2 != ''
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
path: ${{ steps.prep.outputs.file2 }}
archive: false
retention-days: 14

- name: Twister log 3
id: log3
if: always() && steps.prep.outputs.file3 != ''
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
path: ${{ steps.prep.outputs.file3 }}
archive: false
retention-days: 14

- name: Twister log 4
id: log4
if: always() && steps.prep.outputs.file4 != ''
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
path: ${{ steps.prep.outputs.file4 }}
archive: false
retention-days: 14

- name: Twister log 5
id: log5
if: always() && steps.prep.outputs.file5 != ''
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
pattern: result-*
path: results
path: ${{ steps.prep.outputs.file5 }}
archive: false
retention-days: 14

- name: Comment on the pull request
- name: Twister log 6
id: log6
if: always() && steps.prep.outputs.file6 != ''
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
path: ${{ steps.prep.outputs.file6 }}
archive: false
retention-days: 14

- name: Twister log 7
id: log7
if: always() && steps.prep.outputs.file7 != ''
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
path: ${{ steps.prep.outputs.file7 }}
archive: false
retention-days: 14

- name: Twister log 8
id: log8
if: always() && steps.prep.outputs.file8 != ''
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
path: ${{ steps.prep.outputs.file8 }}
archive: false
retention-days: 14

- name: Comment the results on the pull request
if: always()
shell: bash
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_SHA: ${{ github.event.pull_request.head.sha }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
LOGS_URL: ${{ steps.logs.outputs.artifact-url }}
LOG_BOARD_1: ${{ steps.prep.outputs.board1 }}
LOG_URL_1: ${{ steps.log1.outputs.artifact-url }}
LOG_BOARD_2: ${{ steps.prep.outputs.board2 }}
LOG_URL_2: ${{ steps.log2.outputs.artifact-url }}
LOG_BOARD_3: ${{ steps.prep.outputs.board3 }}
LOG_URL_3: ${{ steps.log3.outputs.artifact-url }}
LOG_BOARD_4: ${{ steps.prep.outputs.board4 }}
LOG_URL_4: ${{ steps.log4.outputs.artifact-url }}
LOG_BOARD_5: ${{ steps.prep.outputs.board5 }}
LOG_URL_5: ${{ steps.log5.outputs.artifact-url }}
LOG_BOARD_6: ${{ steps.prep.outputs.board6 }}
LOG_URL_6: ${{ steps.log6.outputs.artifact-url }}
LOG_BOARD_7: ${{ steps.prep.outputs.board7 }}
LOG_URL_7: ${{ steps.log7.outputs.artifact-url }}
LOG_BOARD_8: ${{ steps.prep.outputs.board8 }}
LOG_URL_8: ${{ steps.log8.outputs.artifact-url }}
run: |
set -uo pipefail
MARKER='<!-- ti-platforms-jenkins -->'
API="https://api.github.com/repos/${REPO}"

declare -A LOGURL
for i in 1 2 3 4 5 6 7 8; do
b="LOG_BOARD_$i"; u="LOG_URL_$i"
[[ -n "${!b:-}" ]] && LOGURL["${!b}"]="${!u:-}"
done

ROWS=""
for f in results/*/result.txt; do
[[ -f "$f" ]] || continue
P=$(sed -n 1p "$f"); R=$(sed -n 2p "$f"); B=$(sed -n 3p "$f")
# missing when the run was cancelled before the master finished
touch "$RUNNER_TEMP/platforms.txt"
while read -r _ P R _; do
[[ -n "${P:-}" ]] || continue
case "$R" in SUCCESS) I=":white_check_mark:" ;; FAILURE|UNSTABLE) I=":x:" ;; *) I=":warning:" ;; esac
L="-"; [[ -n "$B" ]] && L="[build](${B}console)"
L="-"; [[ -n "${LOGURL[$P]:-}" ]] && L="[log](${LOGURL[$P]})"
ROWS+=$(printf '| %s | %s %s | %s |\n' "$P" "$I" "$R" "$L")$'\n'
done
[[ -n "$ROWS" ]] || ROWS=$'| - | no result | - |\n'
done < "$RUNNER_TEMP/platforms.txt"
if [[ -z "$ROWS" ]]; then
RES=$(cat "$RUNNER_TEMP/result.txt" 2>/dev/null || echo "not finished")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

2. Early build failures lose their cause 🐞 Bug ◔ Observability

The workflow writes result.txt only after the master wait loop, while the comment step substitutes
not finished when that file is absent. A missing secret, rejected build request, or queue-start
timeout exits before that write, so the pull request comment no longer identifies the failure.
Agent Prompt
## Issue description
Early exits leave no result file, causing the pull request comment to say `not finished` instead of identifying an error or timeout.
## Fix Focus Areas
- .github/workflows/ti_platforms_jenkins.yaml[51-65]
- .github/workflows/ti_platforms_jenkins.yaml[79-95]
- .github/workflows/ti_platforms_jenkins.yaml[161-169]
## Recommended Fix
Initialize an error outcome and restore an exit trap that records it; set a timeout outcome on the queue-start timeout path.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

ROWS=$(printf '| all | :warning: %s | - |\n' "$RES")$'\n'
fi

ALL=""
[[ -n "${LOGS_URL:-}" ]] && ALL=$(printf 'All twister logs in one download: [twister-logs](%s) (kept 14 days)\n\n' "$LOGS_URL")

BODY=$(printf '%s\n## Jenkins build of the TI platforms\n\nCommit `%s`\n\n| Platform | Result | Jenkins |\n| --- | --- | --- |\n%s\n[Workflow run](%s)\n' \
"$MARKER" "${PR_SHA:0:12}" "$ROWS" "$RUN_URL")
BODY=$(printf '%s\n## Jenkins build of the TI platforms\n\nCommit `%s`\n\n| Platform | Result | Log |\n| --- | --- | --- |\n%s\n%s[Workflow run](%s)\n' \
"$MARKER" "${PR_SHA:0:12}" "$ROWS" "$ALL" "$RUN_URL")

# one comment per pull request, updated in place; only a comment of this bot
ID=$(curl -sf -H "Authorization: Bearer $GH_TOKEN" \
Expand Down
Loading