azure-pipelines.yml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. # Gradle
  2. # Build your Java project and run tests with Gradle using a Gradle wrapper script.
  3. # Add steps that analyze code, save build artifacts, deploy, and more:
  4. # https://docs.microsoft.com/azure/devops/pipelines/languages/java
  5. pool:
  6. vmImage: 'Ubuntu-latest'
  7. variables:
  8. revision: $[counter('release-number', 0)]
  9. artifactName: 'Release'
  10. GRADLE_USER_HOME: $(Pipeline.Workspace)/.gradle
  11. steps:
  12. - task: Cache@2
  13. inputs:
  14. key: 'gradle | "$(Agent.OS)" | build.gradle | gradle.properties | src/main/resources/META-INF/accesstransformer.cfg'
  15. restoreKeys: gradle
  16. path: $(GRADLE_USER_HOME)
  17. displayName: Gradle build cache
  18. - powershell: |
  19. (Get-Content ./gradle.properties).Split([Environment]::NewLine) | % {
  20. $kvp = $_.Split('=')
  21. if ($kvp.Count -gt 1) {
  22. $key = $kvp[0] -replace "\.", "_";
  23. $value = $kvp[1];
  24. Write-Host "##vso[task.setvariable variable=javaprops_$key]$value"
  25. }
  26. }
  27. displayName: Create Azure DevOps variables from gradle properties file
  28. - task: Gradle@2
  29. displayName: Create Release Build
  30. inputs:
  31. workingDirectory: ''
  32. options: '--build-cache --max-workers=1 -PCIRevision=$(javaprops_mod_version).$(revision) -PCIType=RELEASE'
  33. gradleWrapperFile: 'gradlew'
  34. gradleOptions: '-Xmx3072m'
  35. javaHomeOption: 'JDKVersion'
  36. jdkVersionOption: '1.8'
  37. jdkArchitectureOption: 'x64'
  38. publishJUnitResults: false
  39. testResultsFiles: '**/TEST-*.xml'
  40. tasks: 'build'
  41. - task: CopyFiles@2
  42. displayName: Copy Release build to artifact staging
  43. inputs:
  44. sourceFolder: './build/libs/'
  45. contents: 'twilightforest-*-universal.jar'
  46. targetFolder: $(build.artifactStagingDirectory)
  47. condition: and(succeeded(), eq(variables['CreateArtifacts'], 'True'))
  48. - task: PublishPipelineArtifact@1
  49. displayName: 'Publish Artifacts'
  50. condition: and(succeeded(), eq(variables['CreateArtifacts'], 'True'))
  51. inputs:
  52. targetPath: '$(Build.ArtifactStagingDirectory)'
  53. artifact: '$(artifactName)'
  54. publishLocation: 'pipeline'
  55. - powershell: |
  56. $rawpath = "pipelineartifact://teamtwilight/projectId/1ef09d39-06cf-41fa-ad98-7258b70c2a72/buildId/$($Env:BUILD_BUILDID)/artifactName/Release"
  57. $path = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($rawpath))
  58. $jar = "twilightforest-$($env:JAVAPROPS_MINECRAFT_VERSION)-$($env:JAVAPROPS_MOD_VERSION).$($env:REVISION)-universal.jar"
  59. $downloadUrl = "https://artprodcus3.artifacts.visualstudio.com/Abaabfa6c-deea-4587-ba05-c308c2597b7a/1ef09d39-06cf-41fa-ad98-7258b70c2a72/_apis/artifact/$($path)0/content?format=file&subPath=%2F$($jar)"
  60. $jobResult = (Get-Culture).TextInfo.ToTitleCase(${env:agent.jobstatus})
  61. $Colour = 65280
  62. if ($jobResult -ne "Succeeded") {
  63. $Colour = 16711680
  64. }
  65. Write-Host "##vso[task.setvariable variable=DiscordMessageColour]$Colour"
  66. $json = [Ordered]@{
  67. title = "Build $jobResult"
  68. url = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)Twilight%20Forest/_build/results?buildId=$($Env:BUILD_BUILDID)&view=results"
  69. color = $Colour
  70. fields = (
  71. [Ordered]@{
  72. name = "Author"
  73. value = "$($env:BUILD_SOURCEVERSIONAUTHOR)"
  74. },
  75. [Ordered]@{
  76. name = "Minecraft Version"
  77. value = "$($env:JAVAPROPS_MINECRAFT_VERSION)"
  78. },
  79. [Ordered]@{
  80. name = "Mod Version"
  81. value = "$($env:JAVAPROPS_MOD_VERSION).$($env:REVISION)"
  82. },
  83. [Ordered]@{
  84. name = "Forge Version"
  85. value = "$($env:JAVAPROPS_FORGE_VERSION)"
  86. },
  87. [Ordered]@{
  88. name = "Commit"
  89. value = "[$(($env:BUILD_SOURCEVERSION).Substring(0, 6))]$($env:BUILD_REPOSITORY_URI)/commit/$($env:BUILD_SOURCEVERSION)"
  90. }
  91. )
  92. }
  93. if ($jobResult -eq "Succeeded") {
  94. $json["fields"] += [Ordered]@{
  95. name = "Download"
  96. value = "$downloadUrl"
  97. }
  98. }
  99. Write-Host "##vso[task.setvariable variable=DiscordMessage]$($json | ConvertTo-Json -Compress)"
  100. displayName: Format discord message
  101. condition: always()
  102. env:
  103. SYSTEM_ACCESSTOKEN: $(System.AccessToken)
  104. - task: ado-discord-webhook@1
  105. displayName: Announce Build to discord
  106. inputs:
  107. channelId: '$(DiscordChannelID)'
  108. webhookKey: '$(DiscordChannelSecret)'
  109. messageType: 'embeds'
  110. embeds: |
  111. [$(DiscordMessage)]
  112. condition: and(always(), eq(variables['CreateArtifacts'], 'True'))
  113. - task: Gradle@2
  114. displayName: Publish to Maven
  115. inputs:
  116. workingDirectory: ''
  117. options: '-PCIRevision=$(javaprops_mod_version).$(revision) -PCIType=RELEASE'
  118. gradleWrapperFile: 'gradlew'
  119. gradleOptions: '-Xmx3072m'
  120. javaHomeOption: 'JDKVersion'
  121. jdkVersionOption: '1.8'
  122. jdkArchitectureOption: 'x64'
  123. publishJUnitResults: false
  124. testResultsFiles: '**/TEST-*.xml'
  125. tasks: 'publish'
  126. condition: and(succeeded(), eq(variables['CreateArtifacts'], 'True'))
  127. env:
  128. ARTIFACTORY_USER: $(Artifactory.User)
  129. ARTIFACTORY_PASS: $(Artifactory.Password)
  130. - script: |
  131. # stop the Gradle daemon to ensure no files are left open (impacting the save cache operation later)
  132. ./gradlew --stop
  133. displayName: Kill Daemon