gatherInfo.groovy 849 B

123456789101112131415161718192021
  1. def call(String branchOverride = null) {
  2. def duration = currentBuild.durationString.replace(' and counting', '')
  3. def commitMsg = sh(returnStdout: true, script: 'git log -1 --pretty=%B').trim()
  4. def author = sh(returnStdout: true, script: 'git log -1 --pretty=%an').trim()
  5. def commitTime = sh(returnStdout: true, script: 'git log -1 --pretty=%ci').trim()
  6. // 优先级:外部传入 > GIT_BRANCH > BRANCH_NAME > unknown
  7. def branch = branchOverride ?: env.GIT_BRANCH ?: env.BRANCH_NAME ?: 'unknown'
  8. // 去掉多余空格
  9. def buildUrl = env.BUILD_URL.replace('http://68.79.46.88:8080', 'https://jenkins.adwebcloud.com')
  10. return [
  11. duration : duration,
  12. commitMsg: commitMsg,
  13. author : author,
  14. commitTime: commitTime,
  15. branch : branch,
  16. buildUrl : buildUrl
  17. ]
  18. }