Skip to content

Commit

Permalink
maketest.sh: Add process cleanup for Windows at the end of testing
Browse files Browse the repository at this point in the history
Signed-off-by: Stewart X Addison <sxa@redhat.com>
  • Loading branch information
sxa committed Nov 18, 2020
1 parent 5060e16 commit 57a5afa
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions maketest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ case `uname` in
;;
esac

if [ "$OSTYPE" = "cygwin" ]; then
export JOBSTARTTIME=$(date -R)
echo PROCESSCATCH: Java processes which are currently on the machine:
powershell -c "Get-Process java | select id,processname,starttime"
fi

if [ "$#" -eq 1 ];then
cd $1/TKG
$MAKE compile
Expand All @@ -29,3 +35,29 @@ else
$MAKE $@
fi

# For now (while this code is being prototyped) I only want this to be
# done while running in jenkins, to avoid a potentially destabilising
# change if people are running other java processes on their local system
set -x
if [ ! -z "$EXECUTOR_NUMBER" ]; then
if [ "$OSTYPE" = "cygwin" ]; then
# Windows code based on https://github.com/AdoptOpenJDK/openjdk-infrastructure/issues/1669#issuecomment-727863096
echo PROCESSCATCH: Showing java processes - one will be the jenkins agent - I will remove any of these created since $JOBSTARTTIME:
powershell -c "Get-Process java"
C=`powershell -c "(Get-Process java | select id,processname,starttime | where {\\$_.StartTime -gt (Get-Date -Date \"$JOBSTARTTIME\")} | measure).count" | tr -d \\\\r`
if [ $C -ne 0 ]; then
echo PROCESSCATCH: I am going to attempt to stop the following ones:
powershell -c "Get-Process java | select id,processname,starttime | where {\$_.StartTime -gt (Get-Date -Date \"$JOBSTARTTIME\")}"
powershell -c "Get-Process java | select id,processname,starttime | where {\$_.StartTime -gt (Get-Date -Date \"$JOBSTARTTIME\")} | stop-process"
echo PROCESSCATCH: Removed processes - here is what is remaining:
powershell -c "Get-Process java"
fi
else
# Non-Windows code from https://ci.adoptopenjdk.net/job/SXA-processCheck
echo PROCESSCATCH: Checking for any leftover java processes on the machine
if ps -fu $USER | grep java | egrep -v "remoting.jar|agent.jar|grep"; then
echo PROCESSCATCH: There are rogue procesess still on the machine
echo PROCESSCATCH: Not killing them for now as this script should be tested more thoroughly first
fi
fi
fi

0 comments on commit 57a5afa

Please sign in to comment.