The following script provides you the licences of Jenkins plugins (e.g. for Open Source compliance checks) read from their pom.xml
file on the respective Github repository.
Before using the script, you have to
- replace
your.jenkins.host.com
with the domain of your Jenkins server - create a Jenkins API token for your user and put it into
~/.jenkins-api-token
Afterwards you can run the script with
./jenkins-plugin-licenses.sh > output.txt
The output format will be Confluence markdown - it can easily be adopted to any other style.
#!/usr/bin/env bash
## Adapt to your Jenkins host
jenkins_host="your.jenkins.host.com"
## Generate an API token for your Jenkins user
jenkins_api_token="$(cat ~/.jenkins-api-token)"
tmpfile=$(mktemp /tmp/jenkins-plugins.XXXXXX)
read -p "jenkins user: " jenkins_user
curl -u "${jenkins_user}:${jenkins_api_token}" "https://${jenkins_host}/pluginManager/api/json?depth=1" | jq ".plugins" > ${tmpfile}
# cat ${tmpfile} | jq .
echo "|| Plugin Name || Short Name || Version || Jenkins / Github URL || License ||"
cat ${tmpfile} | jq ".[] | {longName: .longName, shortName: .shortName, url: .url, version: .version}" | jq -s . | jq -r '.[]|[.longName, .shortName, .version, .url] | @tsv' |
while IFS=$'\t' read -r long short version url; do
github_url=$(curl "https://plugins.jenkins.io/${short}" | egrep -o "(http(s)?://github.com){1}[^'\"]+" | head -1)
raw_content_url=$(echo $github_url | sed s/github.com/raw.githubusercontent.com/g | sed s/blob\\///g)
pom_content=$(curl "${raw_content_url}/master/pom.xml")
license_name=$(echo "$pom_content" | xpath '//project/licenses/license/name/text()')
license_url=$(echo "${pom_content}" | xpath '//project/licenses/license/url/text()')
echo "| ${long} | ${short} | ${version} | ${url} ${github_url} | [${license_name}|${license_url}] [pom.xml|${raw_content_url}/master/pom.xml] |"
done
lovely! I customized this to download
update-center json
and then runjq
andxpath
to get license name, and finally dosort | uniq | sort -bgr
to get count of plugins by license. Here's my version of script: https://gist.github.com/pmgupte/43f8f8b782b839fd648e13637317cd18