Skip to content

Commit

Permalink
Merge pull request #16 from gounthar/updatecli
Browse files Browse the repository at this point in the history
feat(dependencies): Tracks Jenkins LTS versions.
  • Loading branch information
gounthar authored Nov 27, 2023
2 parents 53a4434 + ca8b71b commit 27d8ba1
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
4 changes: 2 additions & 2 deletions dockerfiles/plugins.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ checks-api:2.0.2
cloudbees-folder:6.858.v898218f3609d
commons-lang3-api:3.13.0-62.v7d18e55f51e2
commons-text-api:1.11.0-94.v3e1f4a_926e49
configuration-as-code:1738.v2d8b_a_b_8a_54b_1
configuration-as-code:1746.vf1673cfe690a
credentials-binding:642.v737c34dea_6c2
credentials:1309.v8835d63eb_d8a_
display-url-api:2.200.vb_9327d658781
Expand All @@ -19,7 +19,7 @@ echarts-api:5.4.0-7
font-awesome-api:6.4.2-1
git-client:4.5.0
git:5.2.1
github-api:1.316-451.v15738eef3414
github-api:1.318-461.v7a_c09c9fa_d63
github-branch-source:1751.v90e17c48a_6a_c
github:1.37.3.1
gradle:2.9
Expand Down
33 changes: 33 additions & 0 deletions updatecli/scripts/jenkins-lts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# This script fetches the Jenkins release data, extracts the LTS version numbers, sorts them, and then outputs a specific version based on a "backward" argument.

# -e causes the script to exit immediately if any command fails.
# -u treats unset variables as an error and exits the script.
set -eu -o pipefail

# Get the "backward" argument, default to 0 if not provided.
# This argument specifies which version to get, starting from 0 for the latest version.
backward=${1:-0}

# Subtract 1 from backward to start from 0.
backward=$((backward + 1))

# Uses the wget command to download the RSS feed of the Jenkins changelog and outputs it to the standard output (-O -).
wget -q -O - https://www.jenkins.io/changelog-stable/rss.xml | \
# Uses awk to extract the LTS (Long-Term Support) version numbers from the downloaded RSS feed.
# It searches for lines containing <title>Jenkins, splits the third field based on spaces, and prints the second element of the resulting array.
awk -F'[<>]' '/<title>Jenkins /{split($3,a," "); print a[2]}' | \
# Sorts the version numbers in ascending order.
# It uses the sort command with the delimiter set to dot (-t.) and sorts numerically (-n) based on the first, second, and third fields (-k1,1n -k2,2n -k3,3n).
sort -t. -k1,1n -k2,2n -k3,3n | \
# Uses awk to get the last version of each unique base version.
# It creates an associative array x with the first and second fields as the key and the whole version number as the value.
# In the END block, it iterates over the array and prints the values.
awk -F. '{x[$1"."$2]=$0} END {for (i in x) print x[i]}' | \
# Sorts the versions again in ascending order.
sort -t. -k1,1n -k2,2n -k3,3n | \
# Uses the tail command to get the "backward" version.
# It gets the last n lines, where n is the "backward" argument.
# Then it uses the head command to get the first line of the result, which is the desired version.
tail -n $backward | head -n 1
47 changes: 47 additions & 0 deletions updatecli/updatecli.d/jenkins-lts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: Bump Jenkins' LTS version in the controller Dockerfile

scms:
default:
kind: github
spec:
user: "{{ .github.user }}"
email: "{{ .github.email }}"
owner: "{{ .github.owner }}"
repository: "{{ .github.repository }}"
token: "{{ requiredEnv .github.token }}"
username: "{{ .github.username }}"
branch: "{{ .github.branch }}"

sources:
JenkinsLatestLTS:
name: Get the latest Jenkins LTS version
kind: shell
spec:
command: bash ./updatecli/scripts/jenkins-lts.sh 0 # source input value passed as argument

conditions:
# Test that the latest LTS Jenkins version exists
jenkinsLatestLTSVersion:
kind: jenkins
sourceid: JenkinsLatestLTS

targets:
setJenkinsLatestLTS:
kind: dockerfile
spec:
file: dockerfiles/Dockerfile
instruction:
keyword: "ARG"
matcher: "JENKINS_VERSION"
sourceid: JenkinsLatestLTS

actions:
default:
kind: github/pullrequest
scmid: default
title: Update Jenkins LTS versions to {{ source "JenkinsLatestLTS" }} in the controller Dockerfile
spec:
labels:
- dependencies
- chore

0 comments on commit 27d8ba1

Please sign in to comment.