diff --git a/.ci/scripts/install-tools.bat b/.ci/scripts/install-tools.bat index 0e9aea0ab9eb..99dcc0006a85 100755 --- a/.ci/scripts/install-tools.bat +++ b/.ci/scripts/install-tools.bat @@ -14,26 +14,39 @@ IF ERRORLEVEL 1 ( ) mkdir %WORKSPACE%\bin -REM If 32 bits then install the GVM accordingly -IF NOT EXIST "%PROGRAMFILES(X86)%" ( - curl -sL -o %WORKSPACE%\bin\gvm.exe https://github.com/andrewkroh/gvm/releases/download/v0.2.2/gvm-windows-386.exe -) - -where /q gvm -IF ERRORLEVEL 1 ( - IF EXIST "%PROGRAMFILES(X86)%" ( - curl -sL -o %WORKSPACE%\bin\gvm.exe https://github.com/andrewkroh/gvm/releases/download/v0.2.2/gvm-windows-amd64.exe - ) ELSE ( - curl -sL -o %WORKSPACE%\bin\gvm.exe https://github.com/andrewkroh/gvm/releases/download/v0.2.2/gvm-windows-386.exe +IF EXIST "%PROGRAMFILES(X86)%" ( + REM Force the gvm installation. + SET GVM_BIN=gvm.exe + curl -L -o %WORKSPACE%\bin\gvm.exe https://github.com/andrewkroh/gvm/releases/download/v0.2.4/gvm-windows-amd64.exe + IF ERRORLEVEL 1 ( + REM gvm installation has failed. + exit /b 1 ) +) ELSE ( + REM Windows 7 workers got a broken gvm installation. + curl -L -o %WORKSPACE%\bin\gvm.exe https://github.com/andrewkroh/gvm/releases/download/v0.2.4/gvm-windows-386.exe IF ERRORLEVEL 1 ( + REM gvm installation has failed. exit /b 1 ) - dir "%WORKSPACE%\bin" /b ) -FOR /f "tokens=*" %%i IN ('"gvm.exe" use %GO_VERSION% --format=batch') DO %%i + +SET GVM_BIN=gvm.exe +WHERE /q %GVM_BIN% +%GVM_BIN% version + +REM Install the given go version +%GVM_BIN% --debug install %GO_VERSION% + +REM Configure the given go version +FOR /f "tokens=*" %%i IN ('"%GVM_BIN%" use %GO_VERSION% --format=batch') DO %%i go env +IF ERRORLEVEL 1 ( + REM go is not configured correctly. + exit /b 1 +) + go get github.com/magefile/mage where mage mage -version @@ -41,9 +54,15 @@ IF ERRORLEVEL 1 ( exit /b 1 ) -if not exist C:\Python38\python.exe ( - REM Install python 3.8. - choco install python -y -r --no-progress --version 3.8.2 || echo ERROR && exit /b +REM Set the USERPROFILE to the previous location to fix issues with chocolatey in windows 2019 +SET PREVIOUS_USERPROFILE=%USERPROFILE% +SET USERPROFILE=%OLD_USERPROFILE% +IF NOT EXIST C:\Python38\python.exe ( + REM Install python 3.8 + choco install python -y -r --no-progress --version 3.8.5 + IF NOT ERRORLEVEL 0 ( + exit /b 1 + ) ) python --version where python @@ -58,3 +77,6 @@ IF ERRORLEVEL 1 ( ) gcc --version where gcc + +REM Reset the USERPROFILE +SET USERPROFILE=%PREVIOUS_USERPROFILE% \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index bf41a6d1539c..776a180bdd80 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -304,7 +304,7 @@ def withBeatsEnv(Map args = [:], Closure body) { def withModule = args.get('withModule', false) def directory = args.get('directory', '') - def goRoot, path, magefile, pythonEnv, testResults, artifacts, gox_flags + def goRoot, path, magefile, pythonEnv, testResults, artifacts, gox_flags, userProfile if(isUnix()) { if (isArm() && is64arm()) { @@ -326,7 +326,8 @@ def withBeatsEnv(Map args = [:], Closure body) { def goArch = is32() ? '386' : 'amd64' def chocoPath = 'C:\\ProgramData\\chocolatey\\bin' def chocoPython3Path = 'C:\\Python38;C:\\Python38\\Scripts' - goRoot = "${env.USERPROFILE}\\.gvm\\versions\\go${GO_VERSION}.windows.${goArch}" + userProfile="${env.WORKSPACE}" + goRoot = "${userProfile}\\.gvm\\versions\\go${GO_VERSION}.windows.${goArch}" path = "${env.WORKSPACE}\\bin;${goRoot}\\bin;${chocoPath};${chocoPython3Path};C:\\tools\\mingw${mingwArch}\\bin;${env.PATH}" magefile = "${env.WORKSPACE}\\.magefile" testResults = "**\\build\\TEST*.xml" @@ -342,6 +343,7 @@ def withBeatsEnv(Map args = [:], Closure body) { "DOCKER_PULL=0", "GOPATH=${env.WORKSPACE}", "GOROOT=${goRoot}", + "GOX_FLAGS=${gox_flags}", "HOME=${env.WORKSPACE}", "MAGEFILE_CACHE=${magefile}", "MODULE=${module}", @@ -350,22 +352,14 @@ def withBeatsEnv(Map args = [:], Closure body) { "RACE_DETECTOR=true", "TEST_COVERAGE=true", "TEST_TAGS=${env.TEST_TAGS},oracle", - "GOX_FLAGS=${gox_flags}" + "OLD_USERPROFILE=${env.USERPROFILE}", + "USERPROFILE=${userProfile}" ]) { if(isDockerInstalled()) { dockerLogin(secret: "${DOCKERELASTIC_SECRET}", registry: "${DOCKER_REGISTRY}") } dir("${env.BASE_DIR}") { - installTools() - if(isUnix()) { - // TODO (2020-04-07): This is a work-around to fix the Beat generator tests. - // See https://github.com/elastic/beats/issues/17787. - sh(label: 'check git config', script: ''' - if [ -z "$(git config --get user.email)" ]; then - git config --global user.email "beatsmachine@users.noreply.github.com" - git config --global user.name "beatsmachine" - fi''') - } + installTools(args) // Skip to upload the generated files by default. def upload = false try { @@ -414,11 +408,19 @@ def fixPermissions(location) { * This method installs the required dependencies that are for some reason not available in the * CI Workers. */ -def installTools() { +def installTools(args) { + def stepHeader = "${args.id?.trim() ? args.id : env.STAGE_NAME}" if(isUnix()) { - retryWithSleep(retries: 2, seconds: 5, backoff: true){ sh(label: "Install Go/Mage/Python/Docker/Terraform ${GO_VERSION}", script: '.ci/scripts/install-tools.sh') } + retryWithSleep(retries: 2, seconds: 5, backoff: true){ sh(label: "${stepHeader} - Install Go/Mage/Python/Docker/Terraform ${GO_VERSION}", script: '.ci/scripts/install-tools.sh') } + // TODO (2020-04-07): This is a work-around to fix the Beat generator tests. + // See https://github.com/elastic/beats/issues/17787. + sh(label: 'check git config', script: ''' + if [ -z "$(git config --get user.email)" ]; then + git config --global user.email "beatsmachine@users.noreply.github.com" + git config --global user.name "beatsmachine" + fi''') } else { - retryWithSleep(retries: 2, seconds: 5, backoff: true){ bat(label: "Install Go/Mage/Python ${GO_VERSION}", script: ".ci/scripts/install-tools.bat") } + retryWithSleep(retries: 2, seconds: 5, backoff: true){ bat(label: "${stepHeader} - Install Go/Mage/Python ${GO_VERSION}", script: ".ci/scripts/install-tools.bat") } } }