Created
February 9, 2022 21:30
-
-
Save tmmvn/d7053ed7e1f91ef9f47fc11ffbb9e3a9 to your computer and use it in GitHub Desktop.
JetBrains Space Gradle Build and Publish with Chat Notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* JetBrains Space Automation | |
* This Kotlin-script file lets you automate build activities | |
* For more info, see https://www.jetbrains.com/help/space/automation.html | |
*/ | |
import kotlinx.coroutines.runBlocking | |
import circlet.pipelines.script.ScriptApi | |
class Chatter constructor(scriptAPI: ScriptApi) { | |
val api = scriptAPI | |
fun postChatMessage(message: String) = runBlocking { | |
val recipient = MessageRecipient.Channel(ChatChannel.FromName("builder")) // Name whatever channel you want to post to | |
val content = ChatMessage.Text(message) | |
api.space().chats.messages.sendMessage(recipient, content) | |
} | |
} | |
job("Build and publish") { | |
container(displayName = "Run publish script", image = "amazoncorretto:17") { // Use a container image you like | |
kotlinScript { api -> | |
val chatter = Chatter(api) | |
chatter.postChatMessage("Starting build for ${api.gitRepositoryName()}:${api.executionNumber()}") | |
chatter.postChatMessage("...building${api.gitBranch()}:${api.gitRevision()}") | |
try { | |
api.gradlew("build") | |
api.gradlew("publish") | |
} | |
catch (ex: Exception) { | |
chatter.postChatMessage("!!!ERROR!!! Build failed: ${ex.message}") | |
} | |
chatter.postChatMessage("...build operation finished for ${api.gitRepositoryName()}:${api.executionNumber()}") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment