netci.groovy 8.5 KB
Newer Older
1 2 3
// Groovy Script: http://www.groovy-lang.org/syntax.html
// Jenkins DSL: https://github.com/jenkinsci/job-dsl-plugin/wiki

4
import jobs.generation.Utilities;
J
Jared Parsons 已提交
5 6
import static Constants.*;

7
def project = GithubProject
J
Jared Parsons 已提交
8 9 10 11 12

class Constants {
    // Number of minutes a build job is given to complete.
    static final BuildTimeLimit = 120;
}
13

14 15 16
static void addLogRotator(def myJob) {
  myJob.with {
    logRotator {
17
      daysToKeep(90)
18
      numToKeep(-1)
19 20
      artifactDaysToKeep(21)
      artifactNumToKeep(-1)
21 22 23 24 25 26 27
    }
  }
}

static void addConcurrentBuild(def myJob, String category) {
  myJob.with {
    concurrentBuild(true)
28 29 30 31 32 33 34
    if (category != null)  {
      throttleConcurrentBuilds {
        throttleDisabled(false)
        maxTotal(0)
        maxPerNode(1)
        categories([category])
      }
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    }
  }
}

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 {
J
Jared Parsons 已提交
60
        absolute(BuildTimeLimit)
61 62 63 64 65 66 67
        abortBuild()
      }
      timestamps()
    }
  }
}

68 69 70
static void addArtifactArchiving(def myJob, String patternString, String excludeString) {
  myJob.with {
    publishers {
71 72
      flexiblePublish {
        conditionalAction {
C
CyrusNajmabadi 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85
          condition {
            status('ABORTED', 'FAILURE')
          }

          publishers {
            archiveArtifacts {
              allowEmpty(true)
              defaultExcludes(false)
              exclude(excludeString)
              fingerprint(false)
              onlyIfSuccessful(false)
              pattern(patternString)
            }
86 87
          }
        }
88 89 90 91 92
      }
    }
  }
}

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
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' {
111
          'pattern'('**/xUnitResults/*.xml')
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 142 143 144 145 146 147 148 149
            '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()
    }
  }
}

150 151
// Generates the standard trigger phrases.  This is the regex which ends up matching lines like:
//  test win32 please
J
Jared Parsons 已提交
152
static String generateTriggerPhrase(String jobName, String opsysName, String triggerKeyword = 'this') {
153 154 155
    return "(?i).*test\\W+(${jobName.replace('_', '/').substring(7)}|${opsysName}|${triggerKeyword}|${opsysName}\\W+${triggerKeyword}|${triggerKeyword}\\W+${opsysName})\\W+please.*";
}

J
Jared Parsons 已提交
156
static void addPullRequestTrigger(def myJob, String jobName, String triggerPhraseText, Boolean triggerPhraseOnly = false) {
157
  myJob.with {
158 159 160 161
    triggers {
      pullRequest {
        admin('Microsoft')
        useGitHubHooks(true)
J
Jared Parsons 已提交
162
        triggerPhrase(triggerPhraseText)
J
Jared Parsons 已提交
163
        onlyTriggerPhrase(triggerPhraseOnly)
164 165 166
        autoCloseFailedPullRequests(false)
        orgWhitelist('Microsoft')
        allowMembersOfWhitelistedOrgsAsAdmin(true)
167
        permitAll(true)
168 169
        extensions {
          commitStatus {
170
            context(jobName.replace('_', '/').substring(7))
171 172 173 174 175 176 177
          }
        }
      }
    }
  }
}

J
Jared Parsons 已提交
178
static void addStandardJob(def myJob, String jobName, String branchName, String triggerPhrase, Boolean triggerPhraseOnly = false) {
179 180 181
  addLogRotator(myJob)
  addWrappers(myJob)

182
  def includePattern = "Binaries/**/*.pdb,Binaries/**/*.xml,Binaries/**/*.log,Binaries/**/*.dmp,Binaries/**/*.zip,Binaries/**/*.png,Binaries/**/*.xml"
183
  def excludePattern = "Binaries/Obj/**,Binaries/Bootstrap/**,Binaries/**/nuget*.zip"
184
  addArtifactArchiving(myJob, includePattern, excludePattern)
185 186

  if (branchName == 'prtest') {
J
Jared Parsons 已提交
187
    addPullRequestTrigger(myJob, jobName, triggerPhrase, triggerPhraseOnly);
188 189 190 191 192 193 194 195
    addScm(myJob, '${sha1}', '+refs/pull/*:refs/remotes/origin/pr/*')
  } else {
    addPushTrigger(myJob)
    addScm(myJob, "*/${branchName}")
    addEmailPublisher(myJob)
  }
}

A
Artur Spychaj 已提交
196
def branchNames = []
197
['master', 'future', 'stabilization', 'future-stabilization', 'hotfixes', 'prtest'].each { branchName ->
A
Artur Spychaj 已提交
198 199 200 201 202
  def shortBranchName = branchName.substring(0, 6)
  def jobBranchName = shortBranchName in branchNames ? branchName : shortBranchName
  branchNames << jobBranchName

  // folder("${jobBranchName}")
203
  ['win', 'linux', 'mac'].each { opsys ->
A
Artur Spychaj 已提交
204
    // folder("${jobBranchName}/${opsys.substring(0, 3)}")
205 206
    ['dbg', 'rel'].each { configuration ->
      if ((configuration == 'dbg') || ((branchName != 'prtest') && (opsys == 'win'))) {
A
Artur Spychaj 已提交
207
        // folder("${jobBranchName}/${opsys.substring(0, 3)}/${configuration}")
208 209
        ['unit32', 'unit64'].each { buildTarget ->
          if ((opsys == 'win') || (buildTarget == 'unit32')) {
A
Artur Spychaj 已提交
210
            def jobName = "roslyn_${jobBranchName}_${opsys.substring(0, 3)}_${configuration}_${buildTarget}"
211 212 213 214
            def myJob = job(jobName) {
              description('')
            }

215 216 217 218 219 220 221 222 223 224 225
            // Generate the PR trigger phrase for this job.
            String triggerKeyword = '';
            switch (buildTarget) {
              case 'unit32':
                triggerKeyword =  '(unit|unit32|unit\\W+32)';
                break;
              case 'unit64':
                triggerKeyword = '(unit|unit64|unit\\W+64)';
                break;
            }
            String triggerPhrase = generateTriggerPhrase(jobName, opsys, triggerKeyword);
J
Jared Parsons 已提交
226
            Boolean triggerPhraseOnly = false;
227

228 229 230 231
            switch (opsys) {
              case 'win':
                myJob.with {
                  steps {
232
                    batchFile("""set TEMP=%WORKSPACE%\\Binaries\\Temp
233
mkdir %TEMP%
234
set TMP=%TEMP%
L
Larry Golding 已提交
235
.\\cibuild.cmd ${(configuration == 'dbg') ? '/debug' : '/release'} ${(buildTarget == 'unit32') ? '/test32' : '/test64'}""")
236
                  }
237
                }
238
                Utilities.setMachineAffinity(myJob, 'Windows_NT', 'latest-or-auto')
239 240
                // Generic throttling for Windows, no category
                addConcurrentBuild(myJob, null)
241 242 243 244 245
                break;
              case 'linux':
                myJob.with {
                  label('ubuntu-fast')
                  steps {
246
                    shell("./cibuild.sh --nocache --debug")
247
                  }
248
                }
249
                addConcurrentBuild(myJob, 'roslyn/lin/unit')
250 251 252 253 254
                break;
              case 'mac':
                myJob.with {
                  label('mac-roslyn')
                  steps {
255
                    shell("./cibuild.sh --nocache --debug")
256 257
                  }
                }
258
                addConcurrentBuild(myJob, 'roslyn/mac/unit')
J
Jared Parsons 已提交
259
                triggerPhraseOnly = true;
260
                break;
261 262 263
            }

            addUnitPublisher(myJob)
J
Jared Parsons 已提交
264
            addStandardJob(myJob, jobName, branchName, triggerPhrase, triggerPhraseOnly);
265 266 267 268 269
          }
        }
      }
    }
  }
270

J
Jared Parsons 已提交
271 272 273 274
  def determinismJobName = "roslyn_${jobBranchName}_determinism"
  def determinismJob = job(determinismJobName) {
    description('')
  }
275

J
Jared Parsons 已提交
276 277 278 279
  determinismJob.with {
    label('windows-roslyn')
    steps {
      batchFile("""set TEMP=%WORKSPACE%\\Binaries\\Temp
280 281 282 283
mkdir %TEMP%
set TMP=%TEMP%
.\\cibuild.cmd /testDeterminism""")
    }
284
  }
J
Jared Parsons 已提交
285

286
  Utilities.setMachineAffinity(determinismJob, 'Windows_NT', 'latest-or-auto')
J
Jared Parsons 已提交
287
  addConcurrentBuild(determinismJob, null)
J
Jared Parsons 已提交
288
  addStandardJob(determinismJob, determinismJobName, branchName,  "(?i).*test\\W+determinism.*", true);
289
}
290