Skip to content

Instantly share code, notes, and snippets.

@tmmvn
Created February 9, 2022 21:30
Show Gist options
  • Save tmmvn/d7053ed7e1f91ef9f47fc11ffbb9e3a9 to your computer and use it in GitHub Desktop.
Save tmmvn/d7053ed7e1f91ef9f47fc11ffbb9e3a9 to your computer and use it in GitHub Desktop.
JetBrains Space Gradle Build and Publish with Chat Notifications
/**
* 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