diff --git a/netci.groovy b/netci.groovy index 1d580b8cd..50dc7b3a1 100644 --- a/netci.groovy +++ b/netci.groovy @@ -24,6 +24,7 @@ def static getBuildJobName(def configuration, def os) { // Calculate job name def jobName = getBuildJobName(configuration, os) def buildCommand = ''; + def postBuildCommand = ''; // Calculate the build command if (os == 'Windows_NT') { @@ -31,6 +32,7 @@ def static getBuildJobName(def configuration, def os) { } else { buildCommand = "./scripts/ci_build.sh ${lowerConfiguration}" + postBuildCommand = "./scripts/ci_postbuild.sh ${lowerConfiguration}" } // Create the new job @@ -45,6 +47,16 @@ def static getBuildJobName(def configuration, def os) { else { // Shell shell(buildCommand) + + // Post Build Cleanup + publishers { + postBuildScripts { + steps { + shell(postBuildCommand) + } + onlyIfBuildSucceeds(false) + } + } } } } @@ -67,6 +79,17 @@ def static getBuildJobName(def configuration, def os) { else { // Shell shell(buildCommand) + + // Post Build Cleanup + publishers { + postBuildScripts { + steps { + shell(postBuildCommand) + } + onlyIfBuildSucceeds(false) + } + } + } } } diff --git a/scripts/ci_build.sh b/scripts/ci_build.sh index ac7a2626b..f10e5fa34 100755 --- a/scripts/ci_build.sh +++ b/scripts/ci_build.sh @@ -2,6 +2,16 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" if [[ "$(uname)" == "Linux" ]]; then + # Set Docker Container name to be unique + container_name="" + + #Jenkins + [ ! -z "$BUILD_TAG" ] && container_name="$BUILD_TAG" + #VSO + [ ! -z "$BUILD_BUILDID" ] && container_name="$BUILD_BUILDID" + + export DOTNET_BUILD_CONTAINER_NAME="$container_name" + $SCRIPT_DIR/dockerbuild.sh debian $@ else $SCRIPT_DIR/../build.sh $@ diff --git a/scripts/ci_postbuild.sh b/scripts/ci_postbuild.sh new file mode 100755 index 000000000..344bb77cc --- /dev/null +++ b/scripts/ci_postbuild.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +if [[ "$(uname)" == "Linux" ]]; then + # Set Docker Container name to be unique + container_name="" + + #Jenkins + [ ! -z "$BUILD_TAG" ] && container_name="$BUILD_TAG" + #VSO + [ ! -z "$BUILD_BUILDID" ] && container_name="$BUILD_BUILDID" + + export DOTNET_BUILD_CONTAINER_NAME="$container_name" + + $SCRIPT_DIR/dockerpostbuild.sh $@ +fi + +ret_code=$? +exit $ret_code diff --git a/scripts/dnvm2.sh b/scripts/dnvm2.sh old mode 100644 new mode 100755 diff --git a/scripts/dockerbuild.sh b/scripts/dockerbuild.sh index b4525c074..6540a58b2 100755 --- a/scripts/dockerbuild.sh +++ b/scripts/dockerbuild.sh @@ -21,13 +21,10 @@ echo $DOCKER_HOST_SHARE_DIR docker build -t $DOTNET_BUILD_CONTAINER_TAG scripts/docker/ # Run the build in the container -docker run --rm \ +docker run --rm --sig-proxy=true \ + --name $DOTNET_BUILD_CONTAINER_NAME \ -v $DOCKER_HOST_SHARE_DIR:/opt/code \ -e DOTNET_BUILD_VERSION=$DOTNET_BUILD_VERSION \ $DOTNET_BUILD_CONTAINER_TAG $BUILD_COMMAND $1 -docker run --rm \ - -v $DOCKER_HOST_SHARE_DIR:/opt/code \ - -e DOTNET_BUILD_VERSION=$DOTNET_BUILD_VERSION \ - $DOTNET_BUILD_CONTAINER_TAG chmod a+rw /opt/code diff --git a/scripts/dockerpostbuild.sh b/scripts/dockerpostbuild.sh new file mode 100755 index 000000000..09d60f69d --- /dev/null +++ b/scripts/dockerpostbuild.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + +cd $DIR/.. + +[ -z "$DOTNET_BUILD_CONTAINER_TAG" ] && DOTNET_BUILD_CONTAINER_TAG="dotnetcli-build" +[ -z "$DOTNET_BUILD_CONTAINER_NAME" ] && DOTNET_BUILD_CONTAINER_NAME="dotnetcli-build-container" +[ -z "$DOCKER_HOST_SHARE_DIR" ] && DOCKER_HOST_SHARE_DIR=$(pwd) + +# Build the docker container (will be fast if it is already built) +docker build -t $DOTNET_BUILD_CONTAINER_TAG scripts/docker/ + +# First thing make sure all of our build containers are stopped +docker stop $DOTNET_BUILD_CONTAINER_NAME +docker rm $DOTNET_BUILD_CONTAINER_NAME + +# Remove the sticky bit on directories created by docker so we can delete them +docker run --rm \ + -v $DOCKER_HOST_SHARE_DIR:/opt/code \ + -e DOTNET_BUILD_VERSION=$DOTNET_BUILD_VERSION \ + $DOTNET_BUILD_CONTAINER_TAG chmod -R -t /opt/code + +# And Actually make those directories accessible to be deleted +docker run --rm \ + -v $DOCKER_HOST_SHARE_DIR:/opt/code \ + -e DOTNET_BUILD_VERSION=$DOTNET_BUILD_VERSION \ + $DOTNET_BUILD_CONTAINER_TAG chmod -R a+rwx /opt/code diff --git a/scripts/publish.sh b/scripts/publish.sh old mode 100644 new mode 100755 diff --git a/scripts/repoapi_client.sh b/scripts/repoapi_client.sh old mode 100644 new mode 100755 diff --git a/scripts/windows_dockerbuild.sh b/scripts/windows_dockerbuild.sh old mode 100644 new mode 100755