Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run all steps in a container #44969

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 46 additions & 49 deletions eng/pipelines/templates/jobs/vmr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ parameters:
default: 'Release'

- name: container
type: string
default: ''
type: object
default:
image: ''
name: ''

- name: crossRootFs
type: string
Expand Down Expand Up @@ -115,6 +117,22 @@ jobs:
- job: ${{ parameters.buildName }}_${{ parameters.targetArchitecture }}${{ replace(format('_BuildPass{0}', coalesce(parameters.buildPass, '1')), '_BuildPass1', '') }}
pool: ${{ parameters.pool }}

# 1ES pipeline template requires that the container is specified in the job level.
# If we are using a container image, we set the container to correct name.
# Otherwise, we set the container to host so that the job runs on the host agent.
${{ if eq(variables['System.TeamProject'], 'internal') }}:
${{ if ne(parameters.container.name, '') }}:
container: ${{ parameters.container.name }}
${{ else }}:
container: host

# For public projects, we always use the container image if it is specified.
${{ else }}:
${{ if ne(parameters.container.image, '') }}:
container:
image: ${{ parameters.container.image }}
options: --privileged

# Currently, CodeQL slows the build down too much
# https://github.com/dotnet/source-build/issues/4276
${{ if and(parameters.isBuiltFromVmr, startswith(parameters.buildName, 'Windows'), eq(variables['System.TeamProject'], 'internal'), ne(variables['Build.Reason'], 'PullRequest')) }}:
Expand Down Expand Up @@ -328,21 +346,25 @@ jobs:
eval tar -ozxf "$previousSdkPath" -C "$(sourcesPath)/.dotnet"
eval rm -f "$previousSdkPath"

echo "##vso[task.setvariable variable=additionalBuildArgs]--with-sdk /vmr/.dotnet"
echo "##vso[task.setvariable variable=additionalBuildArgs]--with-sdk $(sourcesPath)/.dotnet"
fi

docker run --rm -v "$(sourcesPath):/vmr" -w /vmr ${{ parameters.container }} ./prep-source-build.sh $customPrepArgs
./prep-source-build.sh $customPrepArgs
displayName: Prep the Build
workingDirectory: $(sourcesPath)

- script: |
set -ex
df -h

customEnvVars=""
customPreBuildArgs=""
customBuildArgs="--ci --clean-while-building --prepareMachine -c ${{ parameters.configuration }}"

if [[ '${{ parameters.runOnline }}' == 'True' ]]; then
customBuildArgs="$customBuildArgs --online"
else
customPreBuildArgs="$customPreBuildArgs sudo unshare -n"
ellahathaway marked this conversation as resolved.
Show resolved Hide resolved
fi

if [[ '${{ parameters.enablePoison }}' == 'True' ]]; then
Expand Down Expand Up @@ -402,32 +424,14 @@ jobs:

buildArgs="$(additionalBuildArgs) $customBuildArgs $extraBuildProperties"

# Only use Docker when a container is specified
if [[ -n "${{ parameters.container }}" ]]; then
# Allows Arcade to have access to the commit for the build, pass it through to the container
customEnvVars="$customEnvVars BUILD_SOURCEVERSION=$BUILD_SOURCEVERSION"

customEnvVars="$customEnvVars BUILD_BUILDNUMBER=$(Build.BuildNumber)"
for envVar in $customEnvVars; do
customEnvVarsWithBashSyntax="$customEnvVarsWithBashSyntax export $envVar;"
ellahathaway marked this conversation as resolved.
Show resolved Hide resolved
done

customDockerRunArgs=""
for envVar in $customEnvVars; do
customDockerRunArgs="$customDockerRunArgs -e $envVar"
done

if [[ '${{ parameters.runOnline }}' == 'False' ]]; then
customDockerRunArgs="$customDockerRunArgs --network none"
fi

docker run --rm -v "$(sourcesPath):/vmr" -w /vmr $customDockerRunArgs ${{ parameters.container }} ./build.sh $buildArgs
else
for envVar in $customEnvVars; do
customEnvVarsWithBashSyntax="$customEnvVarsWithBashSyntax export $envVar;"
done
cd $(sourcesPath)
eval $customEnvVarsWithBashSyntax
./build.sh $buildArgs
fi
eval $customEnvVarsWithBashSyntax
$customPreBuildArgs ./build.sh $buildArgs
displayName: Build
workingDirectory: $(sourcesPath)

# Only run tests if enabled
- ${{ if eq(parameters.runTests, 'True') }}:
Expand All @@ -448,10 +452,14 @@ jobs:
- script: |
set -ex

dockerVolumeArgs="-v $(sourcesPath):/vmr"
customPreBuildArgs=''
customBuildArgs=''
extraBuildProperties=''

if [[ '${{ parameters.runOnline }}' == 'False' ]]; then
customPreBuildArgs="$customPreBuildArgs sudo"
fi

if [[ ! -z '${{ parameters.targetOS }}' ]]; then
extraBuildProperties="$extraBuildProperties /p:TargetOS=${{ parameters.targetOS }}"
fi
Expand Down Expand Up @@ -481,13 +489,8 @@ jobs:
extraBuildProperties="$extraBuildProperties ${{ parameters.extraProperties }}"
fi

# Only use Docker when a container is specified
if [[ -n "${{ parameters.container }}" ]]; then
docker run --rm $dockerVolumeArgs -w /vmr ${{ parameters.container }} ./build.sh --test --excludeCIBinarylog /bl:artifacts/log/Release/Test.binlog -c ${{ parameters.configuration }} $customBuildArgs $extraBuildProperties $(additionalBuildArgs)
else
cd $(sourcesPath)
./build.sh --test --excludeCIBinarylog /bl:artifacts/log/Release/Test.binlog -c ${{ parameters.configuration }} $customBuildArgs $extraBuildProperties $(additionalBuildArgs)
fi
cd $(sourcesPath)
$customPreBuildArgs ./build.sh --test --excludeCIBinarylog /bl:artifacts/log/Release/Test.binlog $customBuildArgs $extraBuildProperties $(additionalBuildArgs)

displayName: Run Tests
timeoutInMinutes: ${{ variables.runTestsTimeout }}
Expand Down Expand Up @@ -536,30 +539,24 @@ jobs:
targetFolder=$(Build.ArtifactStagingDirectory)/BuildLogs/
mkdir -p ${targetFolder}

# Download rsync if using mariner
if grep -qE "CBL-Mariner|Azure Linux" /etc/os-release; then
sudo tdnf install -y rsync
sudo tdnf clean all
fi

cd "$(sourcesPath)"

find artifacts/log/ -exec rsync -R {} -t ${targetFolder} \;
find artifacts/log/ -exec cp --parents {} ${targetFolder} \;
ellahathaway marked this conversation as resolved.
Show resolved Hide resolved

if [ -d "artifacts/scenario-tests/" ]; then
find artifacts/scenario-tests/ -type f -name "*.binlog" -exec rsync -R {} -t ${targetFolder} \;
find artifacts/scenario-tests/ -type f -name "*.binlog" -exec cp --parents {} ${targetFolder} \;
echo "##vso[task.setvariable variable=hasScenarioTestResults]true"
fi

if [ -d "artifacts/TestResults/" ]; then
find artifacts/TestResults/ -type f -name "*.binlog" -exec rsync -R {} -t ${targetFolder} \;
find artifacts/TestResults/ -type f -name "*.diff" -exec rsync -R {} -t ${targetFolder} \;
find artifacts/TestResults/ -type f -name "Updated*.txt" -exec rsync -R {} -t ${targetFolder} \;
find artifacts/TestResults/ -type f -name "*.trx" -exec rsync -R {} -t ${targetFolder} \;
find artifacts/TestResults/ -type f -name "*.binlog" -exec cp --parents {} ${targetFolder} \;
find artifacts/TestResults/ -type f -name "*.diff" -exec cp --parents {} ${targetFolder} \;
find artifacts/TestResults/ -type f -name "Updated*.txt" -exec cp --parents {} ${targetFolder} \;
find artifacts/TestResults/ -type f -name "*.trx" -exec cp --parents {} ${targetFolder} \;
fi

if [[ "${{ parameters.buildSourceOnly }}" == "True" ]]; then
find artifacts/prebuilt-report/ -exec rsync -R {} -t ${targetFolder} \;
find artifacts/prebuilt-report/ -exec cp --parents {} ${targetFolder} \;
fi
displayName: Prepare BuildLogs staging directory and check assets
continueOnError: true
Expand Down
Loading
Loading