Skip to content

Commit

Permalink
[CI] prepare windows tooling (elastic#22661) (elastic#22851)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v committed Dec 2, 2020
1 parent 9876a02 commit c6914e4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 32 deletions.
54 changes: 38 additions & 16 deletions .ci/scripts/install-tools.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,55 @@ 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
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
Expand All @@ -58,3 +77,6 @@ IF ERRORLEVEL 1 (
)
gcc --version
where gcc

REM Reset the USERPROFILE
SET USERPROFILE=%PREVIOUS_USERPROFILE%
34 changes: 18 additions & 16 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,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()) {
Expand All @@ -324,7 +324,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"
Expand All @@ -340,6 +341,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}",
Expand All @@ -348,22 +350,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 {
Expand Down Expand Up @@ -412,11 +406,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") }
}
}

Expand Down

0 comments on commit c6914e4

Please sign in to comment.