Skip to content

Commit

Permalink
Merge pull request #2 from Liftric/feature/promote-release
Browse files Browse the repository at this point in the history
feat(PromoteRelease): add support for promote release
  • Loading branch information
benjohnde authored Apr 20, 2020
2 parents 2bafb68 + c3bd068 commit 3ab163f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,30 @@ commitsSinceLastTag | Calls git log to receive all commits since the previous ta
createBuildInformation | Creates the octopus build-information file.
uploadBuildInformation | Uploads the created octopus build-information file.
uploadPackage | Uploads the package to octopus.
PromoteReleaseTask | Promotes octopus project from one environment to another

For normale use-cases, only `uploadBuildInformation` are `uploadPackage` are needed to call explicitly. Depending
task will be called implicitly by both as needed.

**Noteworthy**: The build-information can be uploaded before the package itself.
Useful when creating automatic releases and using the commits in the release notes in octopus.

### PromoteReleaseTask
The PromoteReleaseTask has no default implementation and must be created explicitly:
```kotlin
import com.liftric.octopusdeploy.task.PromoteReleaseTask
[...]
tasks {
val devToDemo by creating(PromoteReleaseTask::class) {
projectName.set("example-project")
from.set("dev")
to.set("demo")
}
}
```
Calling `./gradlew devToDemo` on this example will promote the current **from** release of the octopus project **example-project**
to the **to** environment.

## naming
Octopus deploy expects the name and version in the following format: `<name>.<version>.<extension>`

Expand Down
8 changes: 8 additions & 0 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.targets.js.npm.importedPackageDir
import com.liftric.octopusdeploy.task.*

plugins {
java
id("com.liftric.octopus-deploy-plugin") version "whatever"
Expand All @@ -14,6 +17,11 @@ tasks {
.removeSuffix("-")}.${archiveVersion.get()}.${archiveExtension.get()}"
)
}
val devToDemo by creating(PromoteReleaseTask::class) {
projectName.set("example-project")
from.set("dev")
to.set("demo")
}
}
octopus {
// targets the GITROOT/docker-compose.yml ocotpus deploy instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class OctopusDeployPlugin : Plugin<Project> {
overwriteMode = extension.buildInformationOverwriteMode?.name
}
}
project.tasks.withType(PromoteReleaseTask::class.java) {
project.afterEvaluate {
apiKey.set(extension.apiKey ?: error("$extensionName: didn't specify apiKey!"))
octopusUrl.set(extension.serverUrl ?: error("$extensionName: didn't specify serverUrl!"))
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.liftric.octopusdeploy.task

import com.liftric.octopusdeploy.shell
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction

open class PromoteReleaseTask : DefaultTask() {
init {
group = "octopus"
description = "Promotes a release."
outputs.upToDateWhen { false }
}

@Input
val octopusUrl = project.objects.property(String::class.java)

@Input
val apiKey = project.objects.property(String::class.java)

/**
* Target octopus project name
*/
@Input
val projectName = project.objects.property(String::class.java)

/**
* Source octopus environment name
*/
@Input
val from = project.objects.property(String::class.java)

/**
* Target octopus environment name
*/
@Input
val to = project.objects.property(String::class.java)

@TaskAction
fun execute() {
val (exitCode, inputText, errorText) = listOf(
"octo",
"promote-release",
"--server=${octopusUrl.get()}",
"--apiKey=${apiKey.get()}",
"--project=${projectName.get()}",
"--from=${from.get()}",
"--to=${to.get()}"
).joinToString(" ").let { shell(it) }
if (exitCode == 0) {
println(inputText)
println(errorText)
} else {
logger.error("octo promote-release returned non-zero exitCode: $exitCode")
logger.error(inputText)
logger.error(errorText)
throw IllegalStateException("octo promote-release exitCode: $exitCode")
}
}
}

0 comments on commit 3ab163f

Please sign in to comment.