Skip to content

Commit

Permalink
[CI] enable Windows-2016 and support 32 bits build requirements (#19199)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v authored Jul 8, 2020
1 parent 4e62fd2 commit 7dc1fcd
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 25 deletions.
20 changes: 18 additions & 2 deletions .ci/scripts/install-tools.bat
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
set GOPATH=%WORKSPACE%
set MAGEFILE_CACHE=%WORKSPACE%\.magefile
set PATH=%WORKSPACE%\bin;C:\ProgramData\chocolatey\bin;%PATH%
set PATH=%WORKSPACE%\bin;C:\ProgramData\chocolatey\bin;C:\tools\mingw64\bin;%PATH%

where /q curl
IF ERRORLEVEL 1 (
choco install curl -y --no-progress --skipdownloadcache
)
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 (
curl -sL -o %WORKSPACE%\bin\gvm.exe https://github.com/andrewkroh/gvm/releases/download/v0.2.2/gvm-windows-amd64.exe
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
)
)
FOR /f "tokens=*" %%i IN ('"gvm.exe" use %GO_VERSION% --format=batch') DO %%i

Expand All @@ -25,3 +35,9 @@ if not exist C:\Python38\python.exe (
python --version
where python

if not exist C:\tools\mingw64\bin\gcc.exe (
REM Install mingw 5.3.0
choco install mingw -y -r --no-progress --version 5.3.0 || echo ERROR && exit /b
)
gcc --version
where gcc
58 changes: 38 additions & 20 deletions .ci/windows.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ import groovy.transform.Field

/**
List of supported windows versions to be tested with
NOTE:
- 'windows-10' is too slow
- 'windows-2012-r2', 'windows-2008-r2', 'windows-7', 'windows-7-32-bit' are disabled
since we are working on releasing each windows version incrementally.
*/
@Field def windowsVersions = ['windows-2019', 'windows-2016', 'windows-2012-r2', 'windows-10', 'windows-2008-r2', 'windows-7', 'windows-7-32-bit']
@Field def windowsVersions = ['windows-2019', 'windows-2016']

pipeline {
agent { label 'ubuntu && immutable' }
Expand Down Expand Up @@ -66,9 +70,7 @@ pipeline {
gitCheckout(basedir: "${BASE_DIR}", githubNotifyFirstTimeContributor: true)
stashV2(name: 'source', bucket: "${JOB_GCS_BUCKET}", credentialsId: "${JOB_GCS_CREDENTIALS}")
dir("${BASE_DIR}"){
// NOTE: commented to run faster the windows pipeline.
// when required then it can be enabled.
// loadConfigEnvVars()
loadConfigEnvVars()
}
whenTrue(params.debug){
dumpFilteredEnvironment()
Expand Down Expand Up @@ -246,20 +248,21 @@ pipeline {
}
}
steps {
mageTargetWin("Winlogbeat Windows Unit test", "x-pack/winlogbeat", "build unitTest")
mageTargetWin("Winlogbeat x-pack Windows", "x-pack/winlogbeat", "build unitTest")
}
}
stage('Functionbeat'){
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_FUNCTIONBEAT_XPACK != "false"
return params.windowsTest
// NOTE: commented to run all the windows stages.
//return env.BUILD_FUNCTIONBEAT_XPACK != "false"
}
}
stages {
stage('Functionbeat Windows'){
agent { label 'windows-immutable && windows-2019' }
stage('Functionbeat Windows x-pack'){
options { skipDefaultCheckout() }
when {
beforeAgent true
Expand All @@ -268,7 +271,7 @@ pipeline {
}
}
steps {
mageTargetWin("Functionbeat Windows Unit test", "x-pack/functionbeat", "build unitTest")
mageTargetWin("Functionbeat x-pack Windows Unit test", "x-pack/functionbeat", "build unitTest")
}
}
}
Expand Down Expand Up @@ -345,16 +348,22 @@ def mageTargetWin(String context, String directory, String target, String label)
return {
log(level: 'INFO', text: "context=${context} directory=${directory} target=${target} os=${label}")
def immutable = label.equals('windows-7-32-bit') ? 'windows-immutable-32-bit' : 'windows-immutable'
node("${immutable} && ${label}"){
withBeatsEnvWin() {
whenTrue(params.debug) {
dumpFilteredEnvironment()
dumpMageWin()
}

def verboseFlag = params.debug ? "-v" : ""
dir(directory) {
bat(label: "Mage ${target}", script: "mage ${verboseFlag} ${target}")
// NOTE: skip filebeat with windows-2016 since there are some test failures.
if (directory.equals('filebeat') && label.equals('windows-2016')) {
log(level: 'WARN', text: "Skipped stage for the 'filebeat' with 'windows-2016' as long as there are test failures to be analysed.")
} else {
node("${immutable} && ${label}"){
withBeatsEnvWin() {
whenTrue(params.debug) {
dumpFilteredEnvironment()
dumpMageWin()
}

def verboseFlag = params.debug ? "-v" : ""
dir(directory) {
bat(label: "Mage ${target}", script: "mage ${verboseFlag} ${target}")
}
}
}
}
Expand Down Expand Up @@ -407,13 +416,17 @@ def withBeatsEnv(boolean archive, Closure body) {
def withBeatsEnvWin(Closure body) {
final String chocoPath = 'C:\\ProgramData\\chocolatey\\bin'
final String chocoPython3Path = 'C:\\Python38;C:\\Python38\\Scripts'
def goRoot = "${env.USERPROFILE}\\.gvm\\versions\\go${GO_VERSION}.windows.amd64"
// NOTE: to support Windows 7 32 bits the arch in the go context path is required.
def arch = is32bit() ? '386' : 'amd64'
def goRoot = "${env.USERPROFILE}\\.gvm\\versions\\go${GO_VERSION}.windows.${arch}"

withEnv([
"HOME=${env.WORKSPACE}",
"DEV_ARCH=${arch}",
"DEV_OS=windows",
"GOPATH=${env.WORKSPACE}",
"GOROOT=${goRoot}",
"PATH=${env.WORKSPACE}\\bin;${goRoot}\\bin;${chocoPath};${chocoPython3Path};${env.PATH}",
"PATH=${env.WORKSPACE}\\bin;${goRoot}\\bin;${chocoPath};${chocoPython3Path};C:\\tools\\mingw64\\bin;${env.PATH}",
"MAGEFILE_CACHE=${env.WORKSPACE}\\.magefile",
"TEST_COVERAGE=true",
"RACE_DETECTOR=true",
Expand Down Expand Up @@ -448,6 +461,11 @@ def installTools() {
}
}

def is32bit(){
def labels = env.NODE_LABELS
return labels.contains('i386')
}

def goos(){
def labels = env.NODE_LABELS

Expand Down
7 changes: 5 additions & 2 deletions dev-tools/mage/gotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,11 @@ func GoTest(ctx context.Context, params GoTestArgs) error {
args := []string{"test"}
args = append(args, "-v")

if params.Race {
args = append(args, "-race")
// -race is only supported on */amd64
if os.Getenv("DEV_ARCH") == "amd64" {
if params.Race {
args = append(args, "-race")
}
}
if len(params.Tags) > 0 {
args = append(args, "-tags", strings.Join(params.Tags, " "))
Expand Down
6 changes: 5 additions & 1 deletion x-pack/elastic-agent/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ func (Test) All() {
// Unit runs all the unit tests.
func (Test) Unit() error {
mg.Deps(Prepare.Env, Build.TestBinaries)
return RunGo("test", "-race", "-v", "-coverprofile", filepath.Join(buildDir, "coverage.out"), "./...")
raceFlag := ""
if os.Getenv("DEV_ARCH") == "amd64" {
raceFlag = "-race"
}
return RunGo("test", raceFlag, "-v", "-coverprofile", filepath.Join(buildDir, "coverage.out"), "./...")
}

// Coverage takes the coverages report from running all the tests and display the results in the browser.
Expand Down

0 comments on commit 7dc1fcd

Please sign in to comment.