Skip to content

Commit 015d9b1

Browse files
authored
Merge pull request #394 from linuxserver/pr-comment
add PR comment on ci false, switch manifestimage setting to if block
2 parents 7ba6525 + 8e764f1 commit 015d9b1

2 files changed

Lines changed: 44 additions & 8 deletions

File tree

Jenkinsfile

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ pipeline {
7676
script{
7777
env.EXIT_STATUS = ''
7878
env.CI_TEST_ATTEMPTED = ''
79+
env.PUSH_ATTEMPTED = ''
7980
env.LS_RELEASE = sh(
8081
script: '''docker run --rm quay.io/skopeo/stable:v1 inspect docker://ghcr.io/${LS_USER}/${CONTAINER_NAME}:latest 2>/dev/null | jq -r '.Labels.build_version' | awk '{print $3}' | grep '\\-ls' || : ''',
8182
returnStdout: true).trim()
@@ -879,6 +880,9 @@ pipeline {
879880
environment name: 'EXIT_STATUS', value: ''
880881
}
881882
steps {
883+
script{
884+
env.PUSH_ATTEMPTED = 'true'
885+
}
882886
retry_backoff(5,5) {
883887
sh '''#! /bin/bash
884888
set -e
@@ -908,11 +912,18 @@ pipeline {
908912
environment name: 'EXIT_STATUS', value: ''
909913
}
910914
steps {
915+
script{
916+
env.PUSH_ATTEMPTED = 'true'
917+
}
911918
retry_backoff(5,5) {
912919
sh '''#! /bin/bash
913920
set -e
914921
for MANIFESTIMAGE in "${IMAGE}" "${GITLABIMAGE}" "${GITHUBIMAGE}" "${QUAYIMAGE}"; do
915-
[[ ${MANIFESTIMAGE%%/*} =~ \\. ]] && MANIFESTIMAGEPLUS="${MANIFESTIMAGE}" || MANIFESTIMAGEPLUS="docker.io/${MANIFESTIMAGE}"
922+
if [[ "${MANIFESTIMAGE%%/*}" =~ \\. ]]; then
923+
MANIFESTIMAGEPLUS="${MANIFESTIMAGE}"
924+
else
925+
MANIFESTIMAGEPLUS="docker.io/${MANIFESTIMAGE}"
926+
fi
916927
IFS=',' read -ra CACHE <<< "$BUILDCACHE"
917928
for i in "${CACHE[@]}"; do
918929
if [[ "${MANIFESTIMAGEPLUS}" == "$(cut -d "/" -f1 <<< ${i})"* ]]; then
@@ -1080,7 +1091,7 @@ EOF
10801091
}
10811092
script {
10821093
if (env.GITHUBIMAGE =~ /lspipepr/){
1083-
if (env.CI_TEST_ATTEMPTED == "true"){
1094+
if (env.CI_TEST_ATTEMPTED == "true" || env.PUSH_ATTEMPTED == "true"){
10841095
sh '''#! /bin/bash
10851096
# Function to retrieve JSON data from URL
10861097
get_json() {
@@ -1141,14 +1152,21 @@ EOF
11411152
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
11421153
-H "Accept: application/vnd.github.v3+json" \
11431154
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1144-
-d "{\\"body\\": \\"I am a bot, here are the test results for this PR: \\n${CI_URL}\\n${SHELLCHECK_URL}\\n${table}\\"}"
1155+
-d "{\\"body\\": \\"I am a bot, here are the test results for this PR for commit ${COMMIT_SHA:0:7} : \\n${CI_URL}\\n${SHELLCHECK_URL}\\n${table}\\"}"
11451156
else
11461157
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
11471158
-H "Accept: application/vnd.github.v3+json" \
11481159
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1149-
-d "{\\"body\\": \\"I am a bot, here is the pushed image/manifest for this PR: \\n\\n\\`${GITHUBIMAGE}:${META_TAG}\\`\\"}"
1160+
-d "{\\"body\\": \\"I am a bot, here is the pushed image/manifest for this PR for commit ${COMMIT_SHA:0:7} : \\n\\n\\`${GITHUBIMAGE}:${META_TAG}\\`\\"}"
11501161
fi
11511162
'''
1163+
} else {
1164+
sh '''#! /bin/bash
1165+
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1166+
-H "Accept: application/vnd.github.v3+json" \
1167+
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1168+
-d "{\\"body\\": \\"I am a bot, the build for PR commit ${COMMIT_SHA:0:7} failed and as a result no CI test was attempted and no images were pushed.\\"}"
1169+
'''
11521170
}
11531171
}
11541172
}

ansible/roles/repository/templates/Jenkinsfile.j2

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pipeline {
6262
script{
6363
env.EXIT_STATUS = ''
6464
env.CI_TEST_ATTEMPTED = ''
65+
env.PUSH_ATTEMPTED = ''
6566
env.LS_RELEASE = sh(
6667
script: '''docker run --rm quay.io/skopeo/stable:v1 inspect docker://ghcr.io/${LS_USER}/${CONTAINER_NAME}:{{ release_tag }} 2>/dev/null | jq -r '.Labels.build_version' | awk '{print $3}' | grep '\\-ls' || : ''',
6768
returnStdout: true).trim()
@@ -1248,6 +1249,9 @@ pipeline {
12481249
environment name: 'EXIT_STATUS', value: ''
12491250
}
12501251
steps {
1252+
script{
1253+
env.PUSH_ATTEMPTED = 'true'
1254+
}
12511255
retry_backoff(5,5) {
12521256
sh '''#! /bin/bash
12531257
set -e
@@ -1280,11 +1284,18 @@ pipeline {
12801284
environment name: 'EXIT_STATUS', value: ''
12811285
}
12821286
steps {
1287+
script{
1288+
env.PUSH_ATTEMPTED = 'true'
1289+
}
12831290
retry_backoff(5,5) {
12841291
sh '''#! /bin/bash
12851292
set -e
12861293
for MANIFESTIMAGE in "${IMAGE}" "${GITLABIMAGE}" "${GITHUBIMAGE}" "${QUAYIMAGE}"; do
1287-
[[ ${MANIFESTIMAGE%%/*} =~ \\. ]] && MANIFESTIMAGEPLUS="${MANIFESTIMAGE}" || MANIFESTIMAGEPLUS="docker.io/${MANIFESTIMAGE}"
1294+
if [[ "${MANIFESTIMAGE%%/*}" =~ \\. ]]; then
1295+
MANIFESTIMAGEPLUS="${MANIFESTIMAGE}"
1296+
else
1297+
MANIFESTIMAGEPLUS="docker.io/${MANIFESTIMAGE}"
1298+
fi
12881299
IFS=',' read -ra CACHE <<< "$BUILDCACHE"
12891300
for i in "${CACHE[@]}"; do
12901301
if [[ "${MANIFESTIMAGEPLUS}" == "$(cut -d "/" -f1 <<< ${i})"* ]]; then
@@ -1512,7 +1523,7 @@ EOF
15121523
}
15131524
script {
15141525
if (env.GITHUBIMAGE =~ /lspipepr/){
1515-
if (env.CI_TEST_ATTEMPTED == "true"){
1526+
if (env.CI_TEST_ATTEMPTED == "true" || env.PUSH_ATTEMPTED == "true"){
15161527
sh '''#! /bin/bash
15171528
# Function to retrieve JSON data from URL
15181529
get_json() {
@@ -1573,14 +1584,21 @@ EOF
15731584
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
15741585
-H "Accept: application/vnd.github.v3+json" \
15751586
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1576-
-d "{\\"body\\": \\"I am a bot, here are the test results for this PR: \\n${CI_URL}\\n${SHELLCHECK_URL}\\n${table}\\"}"
1587+
-d "{\\"body\\": \\"I am a bot, here are the test results for this PR for commit ${COMMIT_SHA:0:7} : \\n${CI_URL}\\n${SHELLCHECK_URL}\\n${table}\\"}"
15771588
else
15781589
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
15791590
-H "Accept: application/vnd.github.v3+json" \
15801591
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1581-
-d "{\\"body\\": \\"I am a bot, here is the pushed image/manifest for this PR: \\n\\n\\`${GITHUBIMAGE}:${META_TAG}\\`\\"}"
1592+
-d "{\\"body\\": \\"I am a bot, here is the pushed image/manifest for this PR for commit ${COMMIT_SHA:0:7} : \\n\\n\\`${GITHUBIMAGE}:${META_TAG}\\`\\"}"
15821593
fi
15831594
'''
1595+
} else {
1596+
sh '''#! /bin/bash
1597+
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1598+
-H "Accept: application/vnd.github.v3+json" \
1599+
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1600+
-d "{\\"body\\": \\"I am a bot, the build for PR commit ${COMMIT_SHA:0:7} failed and as a result no CI test was attempted and no images were pushed.\\"}"
1601+
'''
15841602
}
15851603
}
15861604
}

0 commit comments

Comments
 (0)