|
| 1 | +pr: |
| 2 | + branches: |
| 3 | + include: |
| 4 | + - master |
| 5 | + |
| 6 | +trigger: |
| 7 | + branches: |
| 8 | + include: |
| 9 | + - master |
| 10 | + |
| 11 | +stages: |
| 12 | + - stage: build_and_test |
| 13 | + jobs: |
| 14 | + - job: unit_tests |
| 15 | + pool: |
| 16 | + name: Networking-ContainerNetworking |
| 17 | + demands: agent.os -equals Linux |
| 18 | + |
| 19 | + container: |
| 20 | + image: containernetworking/pipeline-ci:1.0.4 |
| 21 | + options: "--privileged" |
| 22 | + |
| 23 | + # Go setup for the vmImage: |
| 24 | + # https://github.com/Microsoft/azure-pipelines-image-generation/blob/master/images/linux/scripts/installers/go.sh |
| 25 | + variables: |
| 26 | + GOBIN: "$(GOPATH)/bin" # Go binaries path |
| 27 | + GOPATH: "$(System.DefaultWorkingDirectory)/gopath" # Go workspace path |
| 28 | + modulePath: "$(GOPATH)/src/github.com/Azure/azure-container-networking" # $(build.repository.name)' # Path to the module's code |
| 29 | + |
| 30 | + steps: |
| 31 | + - bash: | |
| 32 | + echo $UID |
| 33 | + sudo rm /run/docker/plugins/test.sock || true |
| 34 | + sudo ip link del dev dummy || true |
| 35 | + displayName: "Set up OS environment" |
| 36 | +
|
| 37 | + - bash: | |
| 38 | + go version |
| 39 | + go env |
| 40 | + mkdir -p '$(GOBIN)' |
| 41 | + mkdir -p '$(GOPATH)/pkg' |
| 42 | + mkdir -p '$(modulePath)' |
| 43 | + shopt -s extglob |
| 44 | + shopt -s dotglob |
| 45 | + mv !(gopath) '$(modulePath)' |
| 46 | + echo '##vso[task.prependpath]$(GOBIN)' |
| 47 | + echo '##vso[task.prependpath]$(GOROOT)/bin' |
| 48 | + name: "GoEnv" |
| 49 | + displayName: "Set up the Go environment" |
| 50 | +
|
| 51 | + - script: | |
| 52 | + echo "##vso[task.setvariable variable=CommitHash;isOutput=true]$(git rev-parse HEAD)" |
| 53 | + BRANCH=$(git rev-parse --abbrev-ref HEAD) |
| 54 | + if [[ "$BRANCH" == "master" ]]; then |
| 55 | + echo "##vso[task.setvariable variable=Tag;isOutput=true]$(git describe --tags --abbrev=0)" |
| 56 | + echo "Set tag to $(git describe --tags --abbrev=0)" |
| 57 | + else |
| 58 | + echo "##vso[task.setvariable variable=Tag;isOutput=true]$(git describe --tags --always --dirty)" |
| 59 | + echo "Set tag to $(git describe --tags --always --dirty)" |
| 60 | + fi |
| 61 | + workingDirectory: "$(modulePath)" |
| 62 | + name: "EnvironmentalVariables" |
| 63 | + displayName: "Set build environmental variables" |
| 64 | + condition: always() |
| 65 | +
|
| 66 | + - script: | |
| 67 | + go get -v -t -d ./... |
| 68 | + if [ -f Gopkg.toml ]; then |
| 69 | + curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh |
| 70 | + fi |
| 71 | + go get github.com/docker/libnetwork/driverapi |
| 72 | + go get github.com/gorilla/mux |
| 73 | + go get github.com/jstemmer/go-junit-report |
| 74 | + go get github.com/axw/gocov/gocov |
| 75 | + go get github.com/AlekSi/gocov-xml |
| 76 | + go get -u gopkg.in/matm/v1/gocov-html |
| 77 | + workingDirectory: "$(modulePath)" |
| 78 | + name: "GoDependencies" |
| 79 | + displayName: "Install Go dependencies" |
| 80 | +
|
| 81 | + - script: | |
| 82 | + echo Build tag is $(EnvironmentalVariables.Tag) |
| 83 | + export GOOS=linux |
| 84 | + make all-binaries VERSION=$(EnvironmentalVariables.Tag) |
| 85 | + export GOOS=windows |
| 86 | + make all-binaries VERSION=$(EnvironmentalVariables.Tag) |
| 87 | + cd output |
| 88 | + sudo find . -mindepth 2 -type f -regextype posix-extended ! -iregex '.*\.(zip|tgz)$' -delete |
| 89 | + sudo find . -mindepth 2 -type f -print -exec mv {} . \; |
| 90 | + sudo rm -R -- */ |
| 91 | + workingDirectory: "$(modulePath)" |
| 92 | + name: "Build" |
| 93 | + displayName: "Build" |
| 94 | +
|
| 95 | + - bash: | |
| 96 | + # run test, echo exit status code to fd 3, pipe output from test to tee, which splits output to stdout and go-junit-report (which converts test output to report.xml), stdout from tee is redirected to fd 4. Take output written to fd 3 (which is the exit code of test), redirect to stdout, pipe to read from stdout then exit with that status code. Read all output from fd 4 (output from tee) and write to top stdout |
| 97 | + { { { { |
| 98 | + sudo -E env "PATH=$PATH" make test-all; |
| 99 | + echo $? >&3; |
| 100 | + } | tee >(go-junit-report > report.xml) >&4; |
| 101 | + } 3>&1; |
| 102 | + } | { read xs; exit $xs; } |
| 103 | + } 4>&1 |
| 104 | + workingDirectory: "$(modulePath)" |
| 105 | + failOnStderr: true |
| 106 | + name: "Test" |
| 107 | + displayName: "Run Tests" |
| 108 | +
|
| 109 | + - bash: | |
| 110 | + bash <(curl -s https://codecov.io/bash) |
| 111 | + gocov convert coverage.out > coverage.json |
| 112 | + gocov-xml < coverage.json > coverage.xml |
| 113 | + workingDirectory: "$(modulePath)" |
| 114 | + name: "Coverage" |
| 115 | + displayName: "Generate Coverage Reports" |
| 116 | + condition: always() |
| 117 | +
|
| 118 | + - task: PublishTestResults@2 |
| 119 | + inputs: |
| 120 | + testRunner: JUnit |
| 121 | + testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml |
| 122 | + condition: always() |
| 123 | + |
| 124 | + - task: PublishCodeCoverageResults@1 |
| 125 | + inputs: |
| 126 | + codeCoverageTool: Cobertura |
| 127 | + summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml |
| 128 | + condition: always() |
| 129 | + |
| 130 | + - task: CopyFiles@2 |
| 131 | + inputs: |
| 132 | + sourceFolder: "$(modulePath)/output" |
| 133 | + targetFolder: $(Build.ArtifactStagingDirectory) |
| 134 | + condition: succeeded() |
| 135 | + |
| 136 | + - task: PublishBuildArtifacts@1 |
| 137 | + inputs: |
| 138 | + artifactName: "output" |
| 139 | + pathtoPublish: "$(Build.ArtifactStagingDirectory)" |
| 140 | + condition: succeeded() |
| 141 | + |
| 142 | + - task: AzureCLI@1 |
| 143 | + inputs: |
| 144 | + azureSubscription: $(ARTIFACT_SUBSCRIPTION) |
| 145 | + scriptLocation: "inlineScript" |
| 146 | + inlineScript: | |
| 147 | + az storage container create -n acn-$(EnvironmentalVariables.CommitHash) --account-name $(STORAGE_ACCOUNT_NAME) --public-access container |
| 148 | + az storage blob upload-batch -d acn-$(EnvironmentalVariables.CommitHash) -s ./output/ --account-name $(STORAGE_ACCOUNT_NAME) |
| 149 | + workingDirectory: "$(modulePath)" |
| 150 | + displayName: Create artifact storage container |
| 151 | + |
| 152 | + - template: e2e-job-template.yaml |
| 153 | + parameters: |
| 154 | + name: "ubuntu_16_04_linux_e2e" |
| 155 | + pipelineBuildImage: "containernetworking/pipeline-ci:1.0.4" |
| 156 | + clusterDefinitionUrl: "https://raw.githubusercontent.com/Azure/azure-container-networking/master/test/e2e/kubernetes/cniLinux.json" |
| 157 | + clusterDefinitionCniTypeKey: "azureCNIURLLinux" |
| 158 | + clusterDefinitionCniBuildOS: "linux" |
| 159 | + clusterDefinitionCniBuildExt: ".tgz" |
| 160 | + |
| 161 | + - template: e2e-job-template.yaml |
| 162 | + parameters: |
| 163 | + name: "windows_e2e" |
| 164 | + pipelineBuildImage: "containernetworking/pipeline-ci:1.0.4" |
| 165 | + clusterDefinitionUrl: "https://raw.githubusercontent.com/Azure/azure-container-networking/master/test/e2e/kubernetes/cniWindows.json" |
| 166 | + clusterDefinitionCniTypeKey: "azureCNIURLWindows" |
| 167 | + clusterDefinitionCniBuildOS: "windows" |
| 168 | + clusterDefinitionCniBuildExt: ".zip" |
| 169 | + |
| 170 | + - stage: cleanup |
| 171 | + jobs: |
| 172 | + - job: delete_remote_artifacts |
| 173 | + pool: |
| 174 | + name: Networking-ContainerNetworking |
| 175 | + demands: agent.os -equals Linux |
| 176 | + container: |
| 177 | + image: containernetworking/pipeline-ci:1.0.4 |
| 178 | + variables: |
| 179 | + Tag: $[ dependencies.unit_tests.outputs['EnvironmentalVariables.Tag'] ] |
| 180 | + |
| 181 | + steps: |
| 182 | + - checkout: none |
| 183 | + - task: AzureCLI@1 |
| 184 | + inputs: |
| 185 | + azureSubscription: $(ARTIFACT_SUBSCRIPTION) |
| 186 | + scriptLocation: "inlineScript" |
| 187 | + inlineScript: | |
| 188 | + export CommitHash=(git rev-parse HEAD) |
| 189 | + az storage container delete -n acn-$CommitHash --account-name $(STORAGE_ACCOUNT_NAME) |
| 190 | + workingDirectory: "$(modulePath)" |
| 191 | + displayName: Cleanup remote Azure storage container |
0 commit comments