netci.groovy 8.1 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
            '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()
    }
  }
}

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

J
Jared Parsons 已提交
146
static void addPullRequestTrigger(def myJob, String jobName, String triggerPhrase, Boolean triggerPhraseOnly = false) {
147
  myJob.with {
148 149 150 151
    triggers {
      pullRequest {
        admin('Microsoft')
        useGitHubHooks(true)
152
        triggerPhrase(triggerPhrase)
J
Jared Parsons 已提交
153
        onlyTriggerPhrase(triggerPhraseOnly)
154 155 156
        autoCloseFailedPullRequests(false)
        orgWhitelist('Microsoft')
        allowMembersOfWhitelistedOrgsAsAdmin(true)
157
        permitAll(true)
158 159
        extensions {
          commitStatus {
160
            context(jobName.replace('_', '/').substring(7))
161 162 163 164 165 166 167
          }
        }
      }
    }
  }
}

168
static void addStandardJob(def myJob, String jobName, String branchName, String triggerPhrase) {
169 170 171
  addLogRotator(myJob)
  addWrappers(myJob)

172
  def includePattern = "Binaries/**/*.pdb,Binaries/**/*.xml,Binaries/**/*.log,Binaries/**/*.dmp,Binaries/**/*.zip,Binaries/**/*.png,Binaries/**/*.xml"
173
  def excludePattern = "Binaries/Obj/**,Binaries/Bootstrap/**,Binaries/**/nuget*.zip"
174
  addArtifactArchiving(myJob, includePattern, excludePattern)
175 176

  if (branchName == 'prtest') {
177
    addPullRequestTrigger(myJob, jobName, triggerPhrase);
178 179 180 181 182 183 184 185
    addScm(myJob, '${sha1}', '+refs/pull/*:refs/remotes/origin/pr/*')
  } else {
    addPushTrigger(myJob)
    addScm(myJob, "*/${branchName}")
    addEmailPublisher(myJob)
  }
}

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

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

205 206 207 208 209 210 211 212 213 214 215
            // 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 已提交
216
            Boolean triggerPhraseOnly = false;
217

218 219 220
            switch (opsys) {
              case 'win':
                myJob.with {
221
                  label('windows-roslyn')
222
                  steps {
223
                    batchFile("""set TEMP=%WORKSPACE%\\Binaries\\Temp
224
mkdir %TEMP%
225 226
set TMP=%TEMP%
.\\cibuild.cmd ${(configuration == 'dbg') ? '/debug' : '/release'} ${(buildTarget == 'unit32') ? '/test32' : '/test64'}""")
227
                  }
228
                }
229 230
                // Generic throttling for Windows, no category
                addConcurrentBuild(myJob, null)
231 232 233 234 235
                break;
              case 'linux':
                myJob.with {
                  label('ubuntu-fast')
                  steps {
236
                    shell("./cibuild.sh --nocache --debug")
237
                  }
238
                }
239
                addConcurrentBuild(myJob, 'roslyn/lin/unit')
240 241 242 243 244
                break;
              case 'mac':
                myJob.with {
                  label('mac-roslyn')
                  steps {
245
                    shell("./cibuild.sh --nocache --debug")
246 247
                  }
                }
248
                addConcurrentBuild(myJob, 'roslyn/mac/unit')
J
Jared Parsons 已提交
249
                triggerPhraseOnly = true;
250
                break;
251 252 253
            }

            addUnitPublisher(myJob)
J
Jared Parsons 已提交
254
            addStandardJob(myJob, jobName, branchName, triggerPhrase, triggerPhraseOnly);
255 256 257 258 259
          }
        }
      }
    }
  }
260

J
Jared Parsons 已提交
261 262 263 264
  def determinismJobName = "roslyn_${jobBranchName}_determinism"
  def determinismJob = job(determinismJobName) {
    description('')
  }
265

J
Jared Parsons 已提交
266 267 268 269
  determinismJob.with {
    label('windows-roslyn')
    steps {
      batchFile("""set TEMP=%WORKSPACE%\\Binaries\\Temp
270 271 272 273
mkdir %TEMP%
set TMP=%TEMP%
.\\cibuild.cmd /testDeterminism""")
    }
274
  }
J
Jared Parsons 已提交
275 276 277

  addConcurrentBuild(determinismJob, null)
  addStandardJob(determinismJob, determinismJobName, branchName, 'determinism', true);
278
}
279