netci.groovy 7.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Groovy Script: http://www.groovy-lang.org/syntax.html
// Jenkins DSL: https://github.com/jenkinsci/job-dsl-plugin/wiki

static void addLogRotator(def myJob) {
  myJob.with {
    logRotator {
      daysToKeep(21)
      numToKeep(-1)
      artifactDaysToKeep(5)
      artifactNumToKeep(25)
    }
  }
}

static void addConcurrentBuild(def myJob, String category) {
  myJob.with {
    concurrentBuild(true)
18 19 20 21 22 23 24
    if (category != null)  {
      throttleConcurrentBuilds {
        throttleDisabled(false)
        maxTotal(0)
        maxPerNode(1)
        categories([category])
      }
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
    }
  }
}

static void addScm(def myJob, String branchName, String refspecName = '') {
  myJob.with {
    scm {
      git {
        remote {
          github('dotnet/roslyn', 'https', 'github.com')
          name('')
          refspec(refspecName)
        }
        branch(branchName)
        wipeOutWorkspace(true)
        shallowClone(true)
      }
    }
  }
}

static void addWrappers(def myJob) {
  myJob.with {
    wrappers {
      timeout {
50
        absolute(120)
51 52 53 54 55 56 57
        abortBuild()
      }
      timestamps()
    }
  }
}

58 59 60
static void addArtifactArchiving(def myJob, String patternString, String excludeString) {
  myJob.with {
    publishers {
61 62
      flexiblePublish {
        conditionalAction {
C
CyrusNajmabadi 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75
          condition {
            status('ABORTED', 'FAILURE')
          }

          publishers {
            archiveArtifacts {
              allowEmpty(true)
              defaultExcludes(false)
              exclude(excludeString)
              fingerprint(false)
              onlyIfSuccessful(false)
              pattern(patternString)
            }
76 77
          }
        }
78 79 80 81 82
      }
    }
  }
}

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
static void addEmailPublisher(def myJob) {
  myJob.with {
    publishers {
      extendedEmail('$DEFAULT_RECIPIENTS, cc:mlinfraswat@microsoft.com', '$DEFAULT_SUBJECT', '$DEFAULT_CONTENT') {
        trigger('Aborted', '$PROJECT_DEFAULT_SUBJECT', '$PROJECT_DEFAULT_CONTENT', null, true, true, true, true)
        trigger('Failure', '$PROJECT_DEFAULT_SUBJECT', '$PROJECT_DEFAULT_CONTENT', null, true, true, true, true)
      }
    }
  }
}

static void addUnitPublisher(def myJob) {
  myJob.with {
    configure { node ->
      node / 'publishers' << {
      'xunit'('plugin': 'xunit@1.97') {
      'types' {
        'XUnitDotNetTestType' {
101
          'pattern'('**/xUnitResults/*.xml')
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
            'skipNoTestFiles'(false)
            'failIfNotNew'(true)
            'deleteOutputFiles'(true)
            'stopProcessingIfError'(true)
          }
        }
        'thresholds' {
          'org.jenkinsci.plugins.xunit.threshold.FailedThreshold' {
            'unstableThreshold'('')
            'unstableNewThreshold'('')
            'failureThreshold'('0')
            'failureNewThreshold'('')
          }
          'org.jenkinsci.plugins.xunit.threshold.SkippedThreshold' {
              'unstableThreshold'('')
              'unstableNewThreshold'('')
              'failureThreshold'('')
              'failureNewThreshold'('')
            }
          }
          'thresholdMode'('1')
          'extraConfiguration' {
            testTimeMargin('3000')
          }
        }
      }
    }
  }
}

static void addPushTrigger(def myJob) {
  myJob.with {
    triggers {
      githubPush()
    }
  }
}

static void addPullRequestTrigger(def myJob, String contextName, String opsysName, String triggerKeyword = 'this', Boolean triggerOnly = false) {
  myJob.with {
142 143 144 145
    triggers {
      pullRequest {
        admin('Microsoft')
        useGitHubHooks(true)
146
        triggerPhrase("(?i).*test\\W+(${contextName.replace('_', '/').substring(7)}|${opsysName}|${triggerKeyword}|${opsysName}\\W+${triggerKeyword}|${triggerKeyword}\\W+${opsysName})\\W+please.*")
147 148 149 150
        onlyTriggerPhrase(triggerOnly)
        autoCloseFailedPullRequests(false)
        orgWhitelist('Microsoft')
        allowMembersOfWhitelistedOrgsAsAdmin(true)
151
        permitAll(true)
152 153 154
        extensions {
          commitStatus {
            context(contextName.replace('_', '/').substring(7))
155 156 157 158 159 160 161
          }
        }
      }
    }
  }
}

162 163 164 165
static void addStandardJob(def myJob, String jobName, String branchName, String buildTarget, String opsys) {
  addLogRotator(myJob)
  addWrappers(myJob)

166
  def includePattern = "Binaries/**/*.pdb,Binaries/**/*.xml,Binaries/**/*.log,Binaries/**/*.dmp,Binaries/**/*.zip,Binaries/**/*.png,Binaries/**/*.xml"
167
  def excludePattern = "Binaries/Obj/**,Binaries/Bootstrap/**,Binaries/**/nuget*.zip"
168
  addArtifactArchiving(myJob, includePattern, excludePattern)
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186

  if (branchName == 'prtest') {
    switch (buildTarget) {
      case 'unit32':
        addPullRequestTrigger(myJob, jobName, opsys, "(unit|unit32|unit\\W+32)")
        break;
      case 'unit64':
        addPullRequestTrigger(myJob, jobName, opsys, '(unit|unit64|unit\\W+64)')
        break;
    }
    addScm(myJob, '${sha1}', '+refs/pull/*:refs/remotes/origin/pr/*')
  } else {
    addPushTrigger(myJob)
    addScm(myJob, "*/${branchName}")
    addEmailPublisher(myJob)
  }
}

A
Artur Spychaj 已提交
187
def branchNames = []
188
['master', 'future', 'stabilization', 'future-stabilization', 'hotfixes', 'prtest'].each { branchName ->
A
Artur Spychaj 已提交
189 190 191 192 193
  def shortBranchName = branchName.substring(0, 6)
  def jobBranchName = shortBranchName in branchNames ? branchName : shortBranchName
  branchNames << jobBranchName

  // folder("${jobBranchName}")
194
  ['win', 'linux', 'mac'].each { opsys ->
A
Artur Spychaj 已提交
195
    // folder("${jobBranchName}/${opsys.substring(0, 3)}")
196 197
    ['dbg', 'rel'].each { configuration ->
      if ((configuration == 'dbg') || ((branchName != 'prtest') && (opsys == 'win'))) {
A
Artur Spychaj 已提交
198
        // folder("${jobBranchName}/${opsys.substring(0, 3)}/${configuration}")
199 200
        ['unit32', 'unit64'].each { buildTarget ->
          if ((opsys == 'win') || (buildTarget == 'unit32')) {
A
Artur Spychaj 已提交
201
            def jobName = "roslyn_${jobBranchName}_${opsys.substring(0, 3)}_${configuration}_${buildTarget}"
202 203 204 205
            def myJob = job(jobName) {
              description('')
            }

206 207 208
            switch (opsys) {
              case 'win':
                myJob.with {
209
                  label('windows-roslyn')
210
                  steps {
211
                    batchFile("""set TEMP=%WORKSPACE%\\Binaries\\Temp
212
mkdir %TEMP%
213 214
set TMP=%TEMP%
.\\cibuild.cmd ${(configuration == 'dbg') ? '/debug' : '/release'} ${(buildTarget == 'unit32') ? '/test32' : '/test64'}""")
215
                  }
216
                }
217 218
                // Generic throttling for Windows, no category
                addConcurrentBuild(myJob, null)
219 220 221 222 223
                break;
              case 'linux':
                myJob.with {
                  label('ubuntu-fast')
                  steps {
224
                    shell("./cibuild.sh --nocache --debug")
225
                  }
226
                }
227
                addConcurrentBuild(myJob, 'roslyn/lin/unit')
228 229 230 231 232
                break;
              case 'mac':
                myJob.with {
                  label('mac-roslyn')
                  steps {
233
                    shell("./cibuild.sh --nocache --debug")
234 235
                  }
                }
236
                addConcurrentBuild(myJob, 'roslyn/mac/unit')
237
                break;
238 239 240
            }

            addUnitPublisher(myJob)
241
            addStandardJob(myJob, jobName, branchName, buildTarget, opsys)
242 243 244 245 246
          }
        }
      }
    }
  }
247

248
  if (branchName != 'prtest') {
A
Artur Spychaj 已提交
249
    def determinismJobName = "roslyn_${jobBranchName}_determinism"
250 251 252
    def determinismJob = job(determinismJobName) {
      description('')
    }
253

254 255 256 257
    determinismJob.with {
      label('windows-roslyn')
      steps {
        batchFile("""set TEMP=%WORKSPACE%\\Binaries\\Temp
258 259 260
mkdir %TEMP%
set TMP=%TEMP%
.\\cibuild.cmd /testDeterminism""")
261
      }
262 263
    }

264 265 266
    addConcurrentBuild(determinismJob, null)
    addStandardJob(determinismJob, determinismJobName, branchName, "unit32", "win")
  }
267
}
268