@@ -16,6 +16,7 @@ pipeline {
16
16
GITHUB_TOKEN = credentials(' 498b4638-2d02-4ce5-832d-8a57d01d97ab' )
17
17
GITLAB_TOKEN = credentials(' b6f0f1dd-6952-4cf6-95d1-9c06380283f0' )
18
18
GITLAB_NAMESPACE = credentials(' gitlab-namespace-id' )
19
+ DOCKERHUB_TOKEN = credentials(' docker-hub-ci-pat' )
19
20
BUILD_VERSION_ARG = ' OS'
20
21
LS_USER = ' linuxserver'
21
22
LS_REPO = ' docker-baseimage-debian'
@@ -58,11 +59,16 @@ pipeline {
58
59
env. COMMIT_SHA = sh(
59
60
script : ''' git rev-parse HEAD''' ,
60
61
returnStdout : true ). trim()
62
+ env. GH_DEFAULT_BRANCH = sh(
63
+ script : ''' git remote show origin | grep "HEAD branch:" | sed 's|.*HEAD branch: ||' ''' ,
64
+ returnStdout : true ). trim()
61
65
env. CODE_URL = ' https://github.com/' + env. LS_USER + ' /' + env. LS_REPO + ' /commit/' + env. GIT_COMMIT
62
66
env. DOCKERHUB_LINK = ' https://hub.docker.com/r/' + env. DOCKERHUB_IMAGE + ' /tags/'
63
67
env. PULL_REQUEST = env. CHANGE_ID
64
68
env. TEMPLATED_FILES = ' Jenkinsfile README.md LICENSE .editorconfig ./.github/CONTRIBUTING.md ./.github/FUNDING.yml ./.github/ISSUE_TEMPLATE/config.yml ./.github/ISSUE_TEMPLATE/issue.bug.yml ./.github/ISSUE_TEMPLATE/issue.feature.yml ./.github/PULL_REQUEST_TEMPLATE.md ./.github/workflows/external_trigger_scheduler.yml ./.github/workflows/greetings.yml ./.github/workflows/package_trigger_scheduler.yml ./.github/workflows/call_issue_pr_tracker.yml ./.github/workflows/call_issues_cron.yml ./.github/workflows/permissions.yml ./.github/workflows/external_trigger.yml ./.github/workflows/package_trigger.yml'
65
69
}
70
+ sh ''' #! /bin/bash
71
+ echo "The default github branch detected as ${GH_DEFAULT_BRANCH}" '''
66
72
script{
67
73
env. LS_RELEASE_NUMBER = sh(
68
74
script : ''' echo ${LS_RELEASE} |sed 's/^.*-ls//g' ''' ,
@@ -118,7 +124,7 @@ pipeline {
118
124
steps{
119
125
script{
120
126
env. EXT_RELEASE_CLEAN = sh(
121
- script : ''' echo ${EXT_RELEASE} | sed 's/[~,%@+;:/]//g' ''' ,
127
+ script : ''' echo ${EXT_RELEASE} | sed 's/[~,%@+;:/ ]//g' ''' ,
122
128
returnStdout : true ). trim()
123
129
124
130
def semver = env. EXT_RELEASE_CLEAN =~ / (\d +)\. (\d +)\. (\d +)/
@@ -136,7 +142,7 @@ pipeline {
136
142
}
137
143
138
144
if (env. SEMVER != null ) {
139
- if (BRANCH_NAME != " master " && BRANCH_NAME != " main " ) {
145
+ if (BRANCH_NAME != " ${ env.GH_DEFAULT_BRANCH } " ) {
140
146
env. SEMVER = " ${ env.SEMVER} -${ BRANCH_NAME} "
141
147
}
142
148
println (" SEMVER: ${ env.SEMVER} " )
@@ -254,92 +260,125 @@ pipeline {
254
260
}
255
261
}
256
262
steps {
257
- sh ''' #! /bin/bash
258
- set -e
259
- TEMPDIR=$(mktemp -d)
260
- docker pull ghcr.io/linuxserver/jenkins-builder:latest
261
- docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH=bullseye -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
262
- # Stage 1 - Jenkinsfile update
263
- if [[ "$(md5sum Jenkinsfile | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile | awk '{ print $1 }')" ]]; then
264
- mkdir -p ${TEMPDIR}/repo
265
- git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
266
- cd ${TEMPDIR}/repo/${LS_REPO}
267
- git checkout -f bullseye
268
- cp ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile ${TEMPDIR}/repo/${LS_REPO}/
269
- git add Jenkinsfile
270
- git commit -m 'Bot Updating Templated Files'
271
- git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
272
- echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
273
- echo "Updating Jenkinsfile"
274
- rm -Rf ${TEMPDIR}
275
- exit 0
276
- else
277
- echo "Jenkinsfile is up to date."
278
- fi
279
- # Stage 2 - Delete old templates
280
- OLD_TEMPLATES=".github/ISSUE_TEMPLATE.md .github/ISSUE_TEMPLATE/issue.bug.md .github/ISSUE_TEMPLATE/issue.feature.md .github/workflows/call_invalid_helper.yml .github/workflows/stale.yml Dockerfile.armhf"
281
- for i in ${OLD_TEMPLATES}; do
282
- if [[ -f "${i}" ]]; then
283
- TEMPLATES_TO_DELETE="${i} ${TEMPLATES_TO_DELETE}"
263
+ withCredentials([
264
+ [
265
+ $class : ' UsernamePasswordMultiBinding' ,
266
+ credentialsId : ' 3f9ba4d5-100d-45b0-a3c4-633fd6061207' ,
267
+ usernameVariable : ' DOCKERUSER' ,
268
+ passwordVariable : ' DOCKERPASS'
269
+ ]
270
+ ]) {
271
+ sh ''' #! /bin/bash
272
+ set -e
273
+ TEMPDIR=$(mktemp -d)
274
+ docker pull ghcr.io/linuxserver/jenkins-builder:latest
275
+ docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH=bullseye -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
276
+ # Stage 1 - Jenkinsfile update
277
+ if [[ "$(md5sum Jenkinsfile | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile | awk '{ print $1 }')" ]]; then
278
+ mkdir -p ${TEMPDIR}/repo
279
+ git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
280
+ cd ${TEMPDIR}/repo/${LS_REPO}
281
+ git checkout -f bullseye
282
+ cp ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile ${TEMPDIR}/repo/${LS_REPO}/
283
+ git add Jenkinsfile
284
+ git commit -m 'Bot Updating Templated Files'
285
+ git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git bullseye
286
+ git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git bullseye
287
+ echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
288
+ echo "Updating Jenkinsfile"
289
+ rm -Rf ${TEMPDIR}
290
+ exit 0
291
+ else
292
+ echo "Jenkinsfile is up to date."
284
293
fi
285
- done
286
- if [[ -n "${TEMPLATES_TO_DELETE}" ]]; then
287
- mkdir -p ${TEMPDIR}/repo
288
- git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
289
- cd ${TEMPDIR}/repo/${LS_REPO}
290
- git checkout -f bullseye
291
- for i in ${TEMPLATES_TO_DELETE}; do
292
- git rm "${i}"
294
+ # Stage 2 - Delete old templates
295
+ OLD_TEMPLATES=".github/ISSUE_TEMPLATE.md .github/ISSUE_TEMPLATE/issue.bug.md .github/ISSUE_TEMPLATE/issue.feature.md .github/workflows/call_invalid_helper.yml .github/workflows/stale.yml Dockerfile.armhf"
296
+ for i in ${OLD_TEMPLATES}; do
297
+ if [[ -f "${i}" ]]; then
298
+ TEMPLATES_TO_DELETE="${i} ${TEMPLATES_TO_DELETE}"
299
+ fi
293
300
done
294
- git commit -m 'Bot Updating Templated Files'
295
- git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
296
- echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
297
- echo "Deleting old and deprecated templates"
298
- rm -Rf ${TEMPDIR}
299
- exit 0
300
- else
301
- echo "No templates to delete"
302
- fi
303
- # Stage 3 - Update templates
304
- CURRENTHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
305
- cd ${TEMPDIR}/docker-${CONTAINER_NAME}
306
- NEWHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
307
- if [[ "${CURRENTHASH}" != "${NEWHASH}" ]] || ! grep -q '.jenkins-external' "${WORKSPACE}/.gitignore" 2>/dev/null; then
308
- mkdir -p ${TEMPDIR}/repo
309
- git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
310
- cd ${TEMPDIR}/repo/${LS_REPO}
311
- git checkout -f bullseye
301
+ if [[ -n "${TEMPLATES_TO_DELETE}" ]]; then
302
+ mkdir -p ${TEMPDIR}/repo
303
+ git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
304
+ cd ${TEMPDIR}/repo/${LS_REPO}
305
+ git checkout -f bullseye
306
+ for i in ${TEMPLATES_TO_DELETE}; do
307
+ git rm "${i}"
308
+ done
309
+ git commit -m 'Bot Updating Templated Files'
310
+ git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git bullseye
311
+ git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git bullseye
312
+ echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
313
+ echo "Deleting old and deprecated templates"
314
+ rm -Rf ${TEMPDIR}
315
+ exit 0
316
+ else
317
+ echo "No templates to delete"
318
+ fi
319
+ # Stage 3 - Update templates
320
+ CURRENTHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
312
321
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
313
- mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/workflows
314
- mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/ISSUE_TEMPLATE
315
- cp --parents ${TEMPLATED_FILES} ${TEMPDIR}/repo/${LS_REPO}/ || :
316
- cp --parents readme-vars.yml ${TEMPDIR}/repo/${LS_REPO}/ || :
317
- cd ${TEMPDIR}/repo/${LS_REPO}/
318
- if ! grep -q '.jenkins-external' .gitignore 2>/dev/null; then
319
- echo ".jenkins-external" >> .gitignore
320
- git add .gitignore
322
+ NEWHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
323
+ if [[ "${CURRENTHASH}" != "${NEWHASH}" ]] || ! grep -q '.jenkins-external' "${WORKSPACE}/.gitignore" 2>/dev/null; then
324
+ mkdir -p ${TEMPDIR}/repo
325
+ git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
326
+ cd ${TEMPDIR}/repo/${LS_REPO}
327
+ git checkout -f bullseye
328
+ cd ${TEMPDIR}/docker-${CONTAINER_NAME}
329
+ mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/workflows
330
+ mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/ISSUE_TEMPLATE
331
+ cp --parents ${TEMPLATED_FILES} ${TEMPDIR}/repo/${LS_REPO}/ || :
332
+ cp --parents readme-vars.yml ${TEMPDIR}/repo/${LS_REPO}/ || :
333
+ cd ${TEMPDIR}/repo/${LS_REPO}/
334
+ if ! grep -q '.jenkins-external' .gitignore 2>/dev/null; then
335
+ echo ".jenkins-external" >> .gitignore
336
+ git add .gitignore
337
+ fi
338
+ git add readme-vars.yml ${TEMPLATED_FILES}
339
+ git commit -m 'Bot Updating Templated Files'
340
+ git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git bullseye
341
+ git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git bullseye
342
+ echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
343
+ else
344
+ echo "false" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
321
345
fi
322
- git add readme-vars.yml ${TEMPLATED_FILES}
323
- git commit -m 'Bot Updating Templated Files'
324
- git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
325
- echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
326
- else
327
- echo "false" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
328
- fi
329
- mkdir -p ${TEMPDIR}/docs
330
- git clone https://github.com/linuxserver/docker-documentation.git ${TEMPDIR}/docs/docker-documentation
331
- if [[ ("${BRANCH_NAME}" == "master") || ("${BRANCH_NAME}" == "main") ]] && [[ (! -f ${TEMPDIR}/docs/docker-documentation/docs/images/docker-${CONTAINER_NAME}.md) || ("$(md5sum ${TEMPDIR}/docs/docker-documentation/docs/images/docker-${CONTAINER_NAME}.md | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md | awk '{ print $1 }')") ]]; then
332
- cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md ${TEMPDIR}/docs/docker-documentation/docs/images/
333
- cd ${TEMPDIR}/docs/docker-documentation
334
- git add docs/images/docker-${CONTAINER_NAME}.md
335
- git commit -m 'Bot Updating Documentation'
336
- git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git --all
337
- fi
338
- rm -Rf ${TEMPDIR}'''
339
- script{
340
- env. FILES_UPDATED = sh(
341
- script : ''' cat /tmp/${COMMIT_SHA}-${BUILD_NUMBER}''' ,
342
- returnStdout : true ). trim()
346
+ mkdir -p ${TEMPDIR}/docs
347
+ git clone https://github.com/linuxserver/docker-documentation.git ${TEMPDIR}/docs/docker-documentation
348
+ if [[ "${BRANCH_NAME}" == "${GH_DEFAULT_BRANCH}" ]] && [[ (! -f ${TEMPDIR}/docs/docker-documentation/docs/images/docker-${CONTAINER_NAME}.md) || ("$(md5sum ${TEMPDIR}/docs/docker-documentation/docs/images/docker-${CONTAINER_NAME}.md | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md | awk '{ print $1 }')") ]]; then
349
+ cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md ${TEMPDIR}/docs/docker-documentation/docs/images/
350
+ cd ${TEMPDIR}/docs/docker-documentation
351
+ GH_DOCS_DEFAULT_BRANCH=$(git remote show origin | grep "HEAD branch:" | sed 's|.*HEAD branch: ||')
352
+ git add docs/images/docker-${CONTAINER_NAME}.md
353
+ git commit -m 'Bot Updating Documentation'
354
+ git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH}
355
+ git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH}
356
+ fi
357
+ # Stage 4 - Sync Readme to Docker Hub
358
+ if [[ "${BRANCH_NAME}" == "${GH_DEFAULT_BRANCH}" ]]; then
359
+ if [[ $(cat ${TEMPDIR}/docker-${CONTAINER_NAME}/README.md | wc -m) > 25000 ]]; then
360
+ echo "Readme is longer than 25,000 characters. Syncing the lite version to Docker Hub"
361
+ DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/README.lite"
362
+ else
363
+ echo "Syncing readme to Docker Hub"
364
+ DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/README.md"
365
+ fi
366
+ DH_TOKEN=$(curl -d '{"username":"'${DOCKERUSER}'", "password":"'${DOCKERHUB_TOKEN}'"}' -H "Content-Type: application/json" -X POST https://hub.docker.com/v2/users/login | jq -r '.token')
367
+ curl -s \
368
+ -H "Authorization: JWT ${DH_TOKEN}" \
369
+ -H "Content-Type: application/json" \
370
+ -X PATCH \
371
+ -d "{\\ "full_description\\ ":$(jq -Rsa . ${DH_README_SYNC_PATH})}" \
372
+ https://hub.docker.com/v2/repositories/${DOCKERHUB_IMAGE} || :
373
+ else
374
+ echo "Not the default Github branch. Skipping readme sync to Docker Hub."
375
+ fi
376
+ rm -Rf ${TEMPDIR}'''
377
+ script{
378
+ env. FILES_UPDATED = sh(
379
+ script : ''' cat /tmp/${COMMIT_SHA}-${BUILD_NUMBER}''' ,
380
+ returnStdout : true ). trim()
381
+ }
343
382
}
344
383
}
345
384
}
@@ -530,7 +569,8 @@ pipeline {
530
569
wait
531
570
git add package_versions.txt
532
571
git commit -m 'Bot Updating Package Versions'
533
- git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
572
+ git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git bullseye
573
+ git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git bullseye
534
574
echo "true" > /tmp/packages-${COMMIT_SHA}-${BUILD_NUMBER}
535
575
echo "Package tag updated, stopping build process"
536
576
else
826
866
) '''
827
867
}
828
868
}
829
- // Use helper container to sync the current README on master to the dockerhub endpoint
830
- stage(' Sync-README' ) {
831
- when {
832
- environment name : ' CHANGE_ID' , value : ' '
833
- environment name : ' EXIT_STATUS' , value : ' '
834
- }
835
- steps {
836
- withCredentials([
837
- [
838
- $class : ' UsernamePasswordMultiBinding' ,
839
- credentialsId : ' 3f9ba4d5-100d-45b0-a3c4-633fd6061207' ,
840
- usernameVariable : ' DOCKERUSER' ,
841
- passwordVariable : ' DOCKERPASS'
842
- ]
843
- ]) {
844
- sh ''' #! /bin/bash
845
- set -e
846
- TEMPDIR=$(mktemp -d)
847
- docker pull ghcr.io/linuxserver/jenkins-builder:latest
848
- docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH="${BRANCH_NAME}" -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
849
- docker pull ghcr.io/linuxserver/readme-sync
850
- docker run --rm=true \
851
- -e DOCKERHUB_USERNAME=$DOCKERUSER \
852
- -e DOCKERHUB_PASSWORD=$DOCKERPASS \
853
- -e GIT_REPOSITORY=${LS_USER}/${LS_REPO} \
854
- -e DOCKER_REPOSITORY=${IMAGE} \
855
- -e GIT_BRANCH=master \
856
- -v ${TEMPDIR}/docker-${CONTAINER_NAME}:/mnt \
857
- ghcr.io/linuxserver/readme-sync bash -c 'node sync'
858
- rm -Rf ${TEMPDIR} '''
859
- }
860
- }
861
- }
862
869
// If this is a Pull request send the CI link as a comment on it
863
870
stage(' Pull Request Comment' ) {
864
871
when {
0 commit comments