Run shellcheck on build (#499)

And fix all the errors and warnings reported
This commit is contained in:
Carlos Sanchez 2017-05-27 18:22:27 +02:00 committed by GitHub
parent 6b5d3f03bf
commit ed1a330c47
5 changed files with 33 additions and 24 deletions

11
Jenkinsfile vendored
View File

@ -13,8 +13,17 @@ node('docker') {
} }
if (!infra.isTrusted()) { if (!infra.isTrusted()) {
stage('shellcheck') {
docker.image('koalaman/shellcheck').inside() {
// run shellcheck ignoring error SC1091
// Not following: /usr/local/bin/jenkins-support was not specified as input
sh "shellcheck -e SC1091 *.sh"
}
}
/* Outside of the trusted.ci environment, we're building and testing /* Outside of the trusted.ci environment, we're building and testing
* the Dockerful in this repository, but not publishing to docker hub * the Dockerfile in this repository, but not publishing to docker hub
*/ */
stage('Build') { stage('Build') {
docker.build('jenkins') docker.build('jenkins')

View File

@ -67,7 +67,7 @@ doDownload() {
url="$JENKINS_UC_DOWNLOAD/plugins/$plugin/$version/${plugin}.hpi" url="$JENKINS_UC_DOWNLOAD/plugins/$plugin/$version/${plugin}.hpi"
echo "Downloading plugin: $plugin from $url" echo "Downloading plugin: $plugin from $url"
curl --connect-timeout ${CURL_CONNECTION_TIMEOUT:-20} --retry ${CURL_RETRY:-5} --retry-delay ${CURL_RETRY_DELAY:-0} --retry-max-time ${CURL_RETRY_MAX_TIME:-60} -s -f -L "$url" -o "$jpi" curl --connect-timeout "${CURL_CONNECTION_TIMEOUT:-20}" --retry "${CURL_RETRY:-5}" --retry-delay "${CURL_RETRY_DELAY:-0}" --retry-max-time "${CURL_RETRY_MAX_TIME:-60}" -s -f -L "$url" -o "$jpi"
return $? return $?
} }
@ -126,13 +126,13 @@ bundledPlugins() {
if [ -f $JENKINS_WAR ] if [ -f $JENKINS_WAR ]
then then
TEMP_PLUGIN_DIR=/tmp/plugintemp.$$ TEMP_PLUGIN_DIR=/tmp/plugintemp.$$
for i in $(jar tf $JENKINS_WAR | egrep '[^detached-]plugins.*\..pi' | sort) for i in $(jar tf $JENKINS_WAR | grep -E '[^detached-]plugins.*\..pi' | sort)
do do
rm -fr $TEMP_PLUGIN_DIR rm -fr $TEMP_PLUGIN_DIR
mkdir -p $TEMP_PLUGIN_DIR mkdir -p $TEMP_PLUGIN_DIR
PLUGIN=$(basename "$i"|cut -f1 -d'.') PLUGIN=$(basename "$i"|cut -f1 -d'.')
(cd $TEMP_PLUGIN_DIR;jar xf "$JENKINS_WAR" "$i";jar xvf "$TEMP_PLUGIN_DIR/$i" META-INF/MANIFEST.MF >/dev/null 2>&1) (cd $TEMP_PLUGIN_DIR;jar xf "$JENKINS_WAR" "$i";jar xvf "$TEMP_PLUGIN_DIR/$i" META-INF/MANIFEST.MF >/dev/null 2>&1)
VER=$(egrep -i Plugin-Version "$TEMP_PLUGIN_DIR/META-INF/MANIFEST.MF"|cut -d: -f2|sed 's/ //') VER=$(grep -E -i Plugin-Version "$TEMP_PLUGIN_DIR/META-INF/MANIFEST.MF"|cut -d: -f2|sed 's/ //')
echo "$PLUGIN:$VER" echo "$PLUGIN:$VER"
done done
rm -fr $TEMP_PLUGIN_DIR rm -fr $TEMP_PLUGIN_DIR
@ -160,22 +160,23 @@ installedPlugins() {
} }
main() { main() {
local plugin plugins version local plugin version
local plugins=()
mkdir -p "$REF_DIR" || exit 1 mkdir -p "$REF_DIR" || exit 1
# Read plugins from stdin or from the command line arguments # Read plugins from stdin or from the command line arguments
if [[ ($# -eq 0) ]]; then if [[ ($# -eq 0) ]]; then
while read line; do while read -r line; do
plugins="${plugins:=} ${line}" plugins+=("${line}")
done done
else else
plugins="$@" plugins=("$@")
fi fi
# Create lockfile manually before first run to make sure any explicit version set is used. # Create lockfile manually before first run to make sure any explicit version set is used.
echo "Creating initial locks..." echo "Creating initial locks..."
for plugin in $plugins; do for plugin in "${plugins[@]}"; do
mkdir "$(getLockFile "${plugin%%:*}")" mkdir "$(getLockFile "${plugin%%:*}")"
done done
@ -183,7 +184,7 @@ main() {
bundledPlugins="$(bundledPlugins)" bundledPlugins="$(bundledPlugins)"
echo "Downloading plugins..." echo "Downloading plugins..."
for plugin in $plugins; do for plugin in "${plugins[@]}"; do
version="" version=""
if [[ $plugin =~ .*:.* ]]; then if [[ $plugin =~ .*:.* ]]; then

View File

@ -54,7 +54,7 @@ then
echo "Analyzing: $JENKINS_PLUGINS_DIR" echo "Analyzing: $JENKINS_PLUGINS_DIR"
for i in "$JENKINS_PLUGINS_DIR"/*/; do for i in "$JENKINS_PLUGINS_DIR"/*/; do
JENKINS_PLUGIN=$(basename "$i") JENKINS_PLUGIN=$(basename "$i")
JENKINS_PLUGIN_VER=$(egrep -i Plugin-Version "$i/META-INF/MANIFEST.MF"|cut -d: -f2|sed 's/ //') JENKINS_PLUGIN_VER=$(grep -E -i Plugin-Version "$i/META-INF/MANIFEST.MF"|cut -d: -f2|sed 's/ //')
echo "$JENKINS_PLUGIN:$JENKINS_PLUGIN_VER" echo "$JENKINS_PLUGIN:$JENKINS_PLUGIN_VER"
done >"$TEMP_ALREADY_INSTALLED" done >"$TEMP_ALREADY_INSTALLED"
else else
@ -68,9 +68,9 @@ else
mkdir -p "$TEMP_PLUGIN_DIR" mkdir -p "$TEMP_PLUGIN_DIR"
PLUGIN=$(basename "$i"|cut -f1 -d'.') PLUGIN=$(basename "$i"|cut -f1 -d'.')
(cd "$TEMP_PLUGIN_DIR" || exit; jar xf "$JENKINS_WAR" "$i"; jar xvf "$TEMP_PLUGIN_DIR/$i" META-INF/MANIFEST.MF >/dev/null 2>&1) (cd "$TEMP_PLUGIN_DIR" || exit; jar xf "$JENKINS_WAR" "$i"; jar xvf "$TEMP_PLUGIN_DIR/$i" META-INF/MANIFEST.MF >/dev/null 2>&1)
VER=$(egrep -i Plugin-Version "$TEMP_PLUGIN_DIR/META-INF/MANIFEST.MF"|cut -d: -f2|sed 's/ //') VER=$(grep -E -i Plugin-Version "$TEMP_PLUGIN_DIR/META-INF/MANIFEST.MF"|cut -d: -f2|sed 's/ //')
echo "$PLUGIN:$VER" echo "$PLUGIN:$VER"
done 3< <(jar tf "$JENKINS_WAR" | egrep '[^detached-]plugins.*\..pi' | sort) > "$TEMP_ALREADY_INSTALLED" done 3< <(jar tf "$JENKINS_WAR" | grep -E '[^detached-]plugins.*\..pi' | sort) > "$TEMP_ALREADY_INSTALLED"
rm -fr "$TEMP_PLUGIN_DIR" rm -fr "$TEMP_PLUGIN_DIR"
else else
rm -f "$TEMP_ALREADY_INSTALLED" rm -f "$TEMP_ALREADY_INSTALLED"
@ -84,7 +84,8 @@ mkdir -p $REF
COUNT_PLUGINS_INSTALLED=0 COUNT_PLUGINS_INSTALLED=0
while read -r spec || [ -n "$spec" ]; do while read -r spec || [ -n "$spec" ]; do
plugin=(${spec//:/ }); plugin=()
IFS=' ' read -r -a plugin <<< "${spec//:/ }"
[[ ${plugin[0]} =~ ^# ]] && continue [[ ${plugin[0]} =~ ^# ]] && continue
[[ ${plugin[0]} =~ ^[[:space:]]*$ ]] && continue [[ ${plugin[0]} =~ ^[[:space:]]*$ ]] && continue
[[ -z ${plugin[1]} ]] && plugin[1]="latest" [[ -z ${plugin[1]} ]] && plugin[1]="latest"

View File

@ -31,7 +31,7 @@ docker-tag() {
get-variant() { get-variant() {
local branch local branch
branch=$(git show-ref | grep $(git rev-list -n 1 HEAD) | tail -1 | rev | cut -d/ -f 1 | rev) branch=$(git show-ref | grep "$(git rev-list -n 1 HEAD)" | tail -1 | rev | cut -d/ -f 1 | rev)
if [ -z "$branch" ]; then if [ -z "$branch" ]; then
>&2 echo "Could not get the current branch name for commit, not in a branch?: $(git rev-list -n 1 HEAD)" >&2 echo "Could not get the current branch name for commit, not in a branch?: $(git rev-list -n 1 HEAD)"
return 1 return 1
@ -44,7 +44,7 @@ get-variant() {
login-token() { login-token() {
# could use jq .token # could use jq .token
curl -q -sSL https://auth.docker.io/token\?service\=registry.docker.io\&scope\=repository:jenkinsci/jenkins:pull | grep -o '"token":"[^"]*"' | cut -d':' -f 2 | xargs echo curl -q -sSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:jenkinsci/jenkins:pull" | grep -o '"token":"[^"]*"' | cut -d':' -f 2 | xargs echo
} }
is-published() { is-published() {
@ -71,7 +71,7 @@ get-digest() {
} }
get-latest-versions() { get-latest-versions() {
curl -q -fsSL https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/maven-metadata.xml | grep '<version>.*</version>' | egrep -o '[0-9]+(\.[0-9]+)+' | sort-versions | uniq | tail -n 20 curl -q -fsSL https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/maven-metadata.xml | grep '<version>.*</version>' | grep -E -o '[0-9]+(\.[0-9]+)+' | sort-versions | uniq | tail -n 20
} }
publish() { publish() {
@ -79,12 +79,10 @@ publish() {
local variant=$2 local variant=$2
local tag="${version}${variant}" local tag="${version}${variant}"
local sha local sha
local build_opts="--no-cache --pull" local build_opts=(--no-cache --pull)
if [ "$dry_run" = true ]; then if [ "$dry_run" = true ]; then
build_opts="" build_opts=()
else
build_opts="--no-cache --pull"
fi fi
local dir=war local dir=war
@ -96,7 +94,7 @@ publish() {
docker build --build-arg "JENKINS_VERSION=$version" \ docker build --build-arg "JENKINS_VERSION=$version" \
--build-arg "JENKINS_SHA=$sha" \ --build-arg "JENKINS_SHA=$sha" \
--tag "jenkinsci/jenkins:${tag}" ${build_opts} . --tag "jenkinsci/jenkins:${tag}" "${build_opts[@]}" .
if [ ! "$dry_run" = true ]; then if [ ! "$dry_run" = true ]; then
docker push "jenkinsci/jenkins:${tag}" docker push "jenkinsci/jenkins:${tag}"

View File

@ -4,12 +4,12 @@
sha() { sha() {
local branch=$1 local branch=$1
git rev-parse $branch git rev-parse "$branch"
} }
version_from_dockerfile() { version_from_dockerfile() {
local branch=$1 local branch=$1
git show $branch:Dockerfile | grep JENKINS_VERSION: | sed -e 's/.*:-\(.*\)}/\1/' git show "$branch:Dockerfile" | grep JENKINS_VERSION: | sed -e 's/.*:-\(.*\)}/\1/'
} }
master_sha=$(sha master) master_sha=$(sha master)