diff --git a/Jenkinsfile b/Jenkinsfile index 7616f2a74..7ce805dec 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -74,10 +74,15 @@ def commonTestUbuntu = { def buildDebUbuntu = { repoName, releaseVersion, sourcePath -> def volumeName = "$name-deb-u1604" - sh "docker volume rm -f $volumeName" + if (env.BRANCH_NAME != '' && env.BRANCH_NAME != 'master') { + volumeName = "${volumeName}.${BRANCH_NAME}" + } + if (sh(script: "docker volume ls -q | grep -q '^$volumeName\$'", returnStatus: true) == 0) { + sh "docker volume rm $volumeName" + } dir('build-scripts/ubuntu-1604') { - sh "./build-$name-docker.sh $sourcePath $releaseVersion" - sh "./build-3rd-parties-docker.sh" + sh "./build-$name-docker.sh \"$sourcePath\" $releaseVersion $volumeName" + sh "./build-3rd-parties-docker.sh $volumeName" } return "$volumeName" } diff --git a/Jenkinsfile.cd b/Jenkinsfile.cd index 7616f2a74..7ce805dec 100644 --- a/Jenkinsfile.cd +++ b/Jenkinsfile.cd @@ -74,10 +74,15 @@ def commonTestUbuntu = { def buildDebUbuntu = { repoName, releaseVersion, sourcePath -> def volumeName = "$name-deb-u1604" - sh "docker volume rm -f $volumeName" + if (env.BRANCH_NAME != '' && env.BRANCH_NAME != 'master') { + volumeName = "${volumeName}.${BRANCH_NAME}" + } + if (sh(script: "docker volume ls -q | grep -q '^$volumeName\$'", returnStatus: true) == 0) { + sh "docker volume rm $volumeName" + } dir('build-scripts/ubuntu-1604') { - sh "./build-$name-docker.sh $sourcePath $releaseVersion" - sh "./build-3rd-parties-docker.sh" + sh "./build-$name-docker.sh \"$sourcePath\" $releaseVersion $volumeName" + sh "./build-3rd-parties-docker.sh $volumeName" } return "$volumeName" } diff --git a/build-scripts/ubuntu-1604/build-3rd-parties-docker.sh b/build-scripts/ubuntu-1604/build-3rd-parties-docker.sh index 4f8ddbb6a..e333bd28a 100755 --- a/build-scripts/ubuntu-1604/build-3rd-parties-docker.sh +++ b/build-scripts/ubuntu-1604/build-3rd-parties-docker.sh @@ -3,22 +3,22 @@ set -x set -e -if [ -z $1 ]; then +if [ -z "$2" ]; then CMD="/root/build-3rd-parties.sh /output" else - CMD=$1 + CMD="$2" fi PKG_NAME=indy-node -IMAGE_NAME=${PKG_NAME}-build-u1604 -OUTPUT_VOLUME_NAME=${PKG_NAME}-deb-u1604 +IMAGE_NAME="${PKG_NAME}-build-u1604" +OUTPUT_VOLUME_NAME="${1:-"${PKG_NAME}-deb-u1604"}" -docker build -t ${PKG_NAME}-build-u1604 -f Dockerfile . -docker volume create --name ${OUTPUT_VOLUME_NAME} +docker build -t "${PKG_NAME}-build-u1604" -f Dockerfile . +docker volume create --name "${OUTPUT_VOLUME_NAME}" docker run \ -i \ --rm \ - -v ${OUTPUT_VOLUME_NAME}:/output \ - ${IMAGE_NAME} \ + -v "${OUTPUT_VOLUME_NAME}:/output" \ + "${IMAGE_NAME}" \ $CMD diff --git a/build-scripts/ubuntu-1604/build-3rd-parties.sh b/build-scripts/ubuntu-1604/build-3rd-parties.sh index c27e0fe22..8888ec3c6 100755 --- a/build-scripts/ubuntu-1604/build-3rd-parties.sh +++ b/build-scripts/ubuntu-1604/build-3rd-parties.sh @@ -3,22 +3,22 @@ set -e set -x -OUTPUT_PATH=${1:-.} +OUTPUT_PATH="${1:-.}" function build_from_pypi { - PACKAGE_NAME=$1 + PACKAGE_NAME="$1" - if [ -z $2 ]; then + if [ -z "$2" ]; then PACKAGE_VERSION="" else PACKAGE_VERSION="==$2" fi - POSTINST_TMP=postinst-${PACKAGE_NAME} - PREREM_TMP=prerm-${PACKAGE_NAME} - cp postinst ${POSTINST_TMP} - cp prerm ${PREREM_TMP} - sed -i 's/{package_name}/python3-'${PACKAGE_NAME}'/' ${POSTINST_TMP} - sed -i 's/{package_name}/python3-'${PACKAGE_NAME}'/' ${PREREM_TMP} + POSTINST_TMP="postinst-${PACKAGE_NAME}" + PREREM_TMP="prerm-${PACKAGE_NAME}" + cp postinst "${POSTINST_TMP}" + cp prerm "${PREREM_TMP}" + sed -i "s/{package_name}/python3-${PACKAGE_NAME}/" "${POSTINST_TMP}" + sed -i "s/{package_name}/python3-${PACKAGE_NAME}/" "${PREREM_TMP}" fpm --input-type "python" \ --output-type "deb" \ @@ -29,16 +29,16 @@ function build_from_pypi { --exclude "*.pyc" \ --exclude "*.pyo" \ --maintainer "Hyperledger " \ - --after-install ${POSTINST_TMP} \ - --before-remove ${PREREM_TMP} \ - --package ${OUTPUT_PATH} \ - ${PACKAGE_NAME}${PACKAGE_VERSION} + --after-install "${POSTINST_TMP}" \ + --before-remove "${PREREM_TMP}" \ + --package "${OUTPUT_PATH}" \ + "${PACKAGE_NAME}${PACKAGE_VERSION}" - rm ${POSTINST_TMP} - rm ${PREREM_TMP} + rm "${POSTINST_TMP}" + rm "${PREREM_TMP}" } # build 3rd parties: # build_from_pypi -build_from_pypi timeout-decorator \ No newline at end of file +build_from_pypi timeout-decorator diff --git a/build-scripts/ubuntu-1604/build-indy-node-docker.sh b/build-scripts/ubuntu-1604/build-indy-node-docker.sh index 8adf2b888..73461fc59 100755 --- a/build-scripts/ubuntu-1604/build-indy-node-docker.sh +++ b/build-scripts/ubuntu-1604/build-indy-node-docker.sh @@ -1,31 +1,31 @@ #!/bin/bash -xe -PKG_SOURCE_PATH=$1 -VERSION=$2 +PKG_SOURCE_PATH="$1" +VERSION="$2" PKG_NAME=indy-node -IMAGE_NAME=${PKG_NAME}-build-u1604 -OUTPUT_VOLUME_NAME=${PKG_NAME}-deb-u1604 +IMAGE_NAME="${PKG_NAME}-build-u1604" +OUTPUT_VOLUME_NAME="${3:-"${PKG_NAME}-deb-u1604"}" -if [[ (-z ${PKG_SOURCE_PATH}) || (-z ${VERSION}) ]]; then - echo "Usage: $0 " +if [[ (-z "${PKG_SOURCE_PATH}") || (-z "${VERSION}") ]]; then + echo "Usage: $0 " exit 1; fi -if [ -z $3 ]; then - CMD="/root/build-"${PKG_NAME}".sh /input ${VERSION} /output" +if [ -z "$4" ]; then + CMD="/root/build-${PKG_NAME}.sh /input ${VERSION} /output" else - CMD=$3 + CMD="$4" fi -docker build -t ${IMAGE_NAME} -f Dockerfile . -docker volume create --name ${OUTPUT_VOLUME_NAME} +docker build -t "${IMAGE_NAME}" -f Dockerfile . +docker volume create --name "${OUTPUT_VOLUME_NAME}" docker run \ -i \ --rm \ - -v ${PKG_SOURCE_PATH}:/input \ - -v ${OUTPUT_VOLUME_NAME}:/output \ - -e PKG_NAME=${PKG_NAME} \ - ${IMAGE_NAME} \ + -v "${PKG_SOURCE_PATH}:/input" \ + -v "${OUTPUT_VOLUME_NAME}:/output" \ + -e PKG_NAME="${PKG_NAME}" \ + "${IMAGE_NAME}" \ $CMD diff --git a/build-scripts/ubuntu-1604/build-indy-node.sh b/build-scripts/ubuntu-1604/build-indy-node.sh index 4674e702f..990248588 100755 --- a/build-scripts/ubuntu-1604/build-indy-node.sh +++ b/build-scripts/ubuntu-1604/build-indy-node.sh @@ -1,21 +1,21 @@ #!/bin/bash -xe -INPUT_PATH=$1 -VERSION=$2 -OUTPUT_PATH=${3:-.} +INPUT_PATH="$1" +VERSION="$2" +OUTPUT_PATH="${3:-.}" PACKAGE_NAME=indy-node # copy the sources to a temporary folder -TMP_DIR=$(mktemp -d) -cp -r ${INPUT_PATH}/. ${TMP_DIR} +TMP_DIR="$(mktemp -d)" +cp -r "${INPUT_PATH}/." "${TMP_DIR}" # prepare the sources -cd ${TMP_DIR}/build-scripts/ubuntu-1604 -./prepare-package.sh ${TMP_DIR} ${VERSION} +cd "${TMP_DIR}/build-scripts/ubuntu-1604" +./prepare-package.sh "${TMP_DIR}" "${VERSION}" -sed -i 's/{package_name}/'${PACKAGE_NAME}'/' "prerm" +sed -i "s/{package_name}/${PACKAGE_NAME}/" "prerm" fpm --input-type "python" \ --output-type "deb" \ @@ -31,8 +31,8 @@ fpm --input-type "python" \ --before-install "preinst_node" \ --after-install "postinst_node" \ --before-remove "prerm" \ - --name ${PACKAGE_NAME} \ - --package ${OUTPUT_PATH} \ - ${TMP_DIR} + --name "${PACKAGE_NAME}" \ + --package "${OUTPUT_PATH}" \ + "${TMP_DIR}" -rm -rf ${TMP_DIR} +rm -rf "${TMP_DIR}"