diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b37a71f..ce40a564 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ -### 0.11.1 - Unreleased +### 0.11.2 - Unreleased + +### 0.11.1 - (2019-Aug) + +* updated README documenting `allow_only_on_success` attribute for approval in stages ### 0.11.0 (2019-Aug-02) diff --git a/README.md b/README.md index 49b34d71..596dad18 100644 --- a/README.md +++ b/README.md @@ -216,7 +216,20 @@ Feel free to improve it! Please note that it is now recommended to declare `format_version` in each `gocd.yaml` file, consistent across all your files. -#### GoCD server version from 19.4.0 and beyond +#### GoCD server verison from 19.8.0 and beyond + +Supports `format_version` value of `6`. In this version, support of `allow_only_on_success` attribute for [approval](#approval) in stage has been added. Setting this attribute to `true` will allow the stage to be manually triggered only if the previous stage has passed successfully. + +Using a newer `format_version` includes all the behavior of the previous versions too. + +```yaml +format_version: 6 +pipelines: + ... +environments: +``` + +#### GoCD server version from 19.4.0 to 19.7.0 Supports `format_version` value of `5`. In this version, support of `username` and `encrypted_password` for [git](#git-material-update) and [hg](#hg-material-update) material has been added. In addition to that, [hg](#hg-material-update) will also support `branch` attribute. @@ -460,12 +473,15 @@ If you need to set associated users or roles: ```yaml approval: type: manual + allow_only_on_success: true roles: - manager users: - john ``` +You can set `allow_only_on_success` to allow manual trigger only if the previous stage run is successful. The default value is `false`. + ## Job [Job](https://docs.gocd.org/current/configuration/configuration_reference.html#job) is a hash starting with jobs name: diff --git a/build.gradle b/build.gradle index 2428793a..304bff3d 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group 'cd.go.plugin.config.yaml' -version "0.11.1" +version "0.11.2" apply plugin: 'java' apply plugin: "com.github.jk1.dependency-license-report" diff --git a/src/main/java/cd/go/plugin/config/yaml/transforms/StageTransform.java b/src/main/java/cd/go/plugin/config/yaml/transforms/StageTransform.java index cdc2cf09..518a14c7 100644 --- a/src/main/java/cd/go/plugin/config/yaml/transforms/StageTransform.java +++ b/src/main/java/cd/go/plugin/config/yaml/transforms/StageTransform.java @@ -25,6 +25,8 @@ public class StageTransform { private static final String JSON_STAGE_APPROVAL_TYPE_FIELD = "type"; private static final String YAML_STAGE_APPROVAL_TYPE_FIELD = "type"; private static final String JSON_STAGE_JOBS_FIELD = "jobs"; + private static final String JSON_STAGE_APPROVAL_ALLOW_ONLY_ON_SUCCESS_FIELD = "allow_only_on_success"; + private static final String YAML_STAGE_APPROVAL_ALLOW_ONLY_ON_SUCCESS_FIELD = "allow_only_on_success"; private static final String JSON_STAGE_APPROVAL_USERS_FIELD = "users"; private static final String YAML_STAGE_APPROVAL_USERS_FIELD = "users"; private static final String JSON_STAGE_APPROVAL_ROLES_FIELD = "roles"; @@ -78,10 +80,10 @@ public Map inverseTransform(Map stage) { addOptionalValue(stageData, stage, JSON_STAGE_FETCH_FIELD, YAML_STAGE_FETCH_FIELD); addOptionalValue(stageData, stage, JSON_STAGE_NEVER_CLEAN_FIELD, YAML_STAGE_KEEP_ARTIFACTS_FIELD); addOptionalValue(stageData, stage, JSON_STAGE_CLEAN_WORK_FIELD, YAML_STAGE_CLEAN_WORK_FIELD); + addOptionalValue(stageData, stage, JSON_STAGE_APPROVAL_ALLOW_ONLY_ON_SUCCESS_FIELD, YAML_STAGE_APPROVAL_ALLOW_ONLY_ON_SUCCESS_FIELD); addInverseApproval(stageData, stage); - Map yamlEnvVariables = environmentTransform.inverseTransform((List>) stage.get(JSON_ENV_VAR_FIELD)); if (yamlEnvVariables != null && yamlEnvVariables.size() > 0) stageData.putAll(yamlEnvVariables); @@ -110,6 +112,7 @@ private void addInverseApproval(Map stageData, Map approvalMap = (Map) approval; addRequiredString(approvalJson, approvalMap, JSON_STAGE_APPROVAL_TYPE_FIELD, YAML_STAGE_APPROVAL_TYPE_FIELD); + addOptionalBoolean(approvalJson, approvalMap, JSON_STAGE_APPROVAL_ALLOW_ONLY_ON_SUCCESS_FIELD, YAML_STAGE_APPROVAL_ALLOW_ONLY_ON_SUCCESS_FIELD); addOptionalStringList(approvalJson, approvalMap, JSON_STAGE_APPROVAL_USERS_FIELD, YAML_STAGE_APPROVAL_USERS_FIELD); addOptionalStringList(approvalJson, approvalMap, JSON_STAGE_APPROVAL_ROLES_FIELD, YAML_STAGE_APPROVAL_ROLES_FIELD); } diff --git a/src/test/java/cd/go/plugin/config/yaml/transforms/StageTransformTest.java b/src/test/java/cd/go/plugin/config/yaml/transforms/StageTransformTest.java index 3a50fcd3..33665f24 100644 --- a/src/test/java/cd/go/plugin/config/yaml/transforms/StageTransformTest.java +++ b/src/test/java/cd/go/plugin/config/yaml/transforms/StageTransformTest.java @@ -34,6 +34,11 @@ public void shouldTransformCompleteStage() throws IOException { testTransform("complete"); } + @Test + public void shouldTransformCompleteStageWithManualApproval() throws IOException { + testTransform("complete_with_manual_approval"); + } + @Test public void shouldTransformShortApprovalStage() throws IOException { testTransform("short_approval"); diff --git a/src/test/resources/examples/rich.gocd.yaml b/src/test/resources/examples/rich.gocd.yaml index e6841ad1..48c40dc6 100644 --- a/src/test/resources/examples/rich.gocd.yaml +++ b/src/test/resources/examples/rich.gocd.yaml @@ -25,6 +25,7 @@ pipelines: # tells plugin that here are pipelines by name clean_workspace: true approval: type: manual + allow_only_on_success: true roles: - manager jobs: diff --git a/src/test/resources/parts/stages/complete_with_manual_approval.json b/src/test/resources/parts/stages/complete_with_manual_approval.json new file mode 100644 index 00000000..486916be --- /dev/null +++ b/src/test/resources/parts/stages/complete_with_manual_approval.json @@ -0,0 +1,30 @@ +{ + "name": "test", + "fetch_materials": true, + "never_cleanup_artifacts": true, + "clean_working_directory": true, + "approval": { + "type": "manual", + "allow_only_on_success": true, + "roles": [ + "manager" + ], + "users": [ + "john" + ] + }, + "environment_variables": [ + { + "name": "TEST_NUM", + "value": "1" + }, + { + "name": "PASSWORD", + "encrypted_value": "!@ESsdD323#sdu" + } + ], + "jobs": [ + null, + null + ] +} diff --git a/src/test/resources/parts/stages/complete_with_manual_approval.yaml b/src/test/resources/parts/stages/complete_with_manual_approval.yaml new file mode 100644 index 00000000..ca780d1e --- /dev/null +++ b/src/test/resources/parts/stages/complete_with_manual_approval.yaml @@ -0,0 +1,18 @@ +test: + fetch_materials: yes + keep_artifacts: yes + clean_workspace: yes + approval: + type: manual + allow_only_on_success: true + roles: + - manager + users: + - john + environment_variables: + TEST_NUM: 1 + secure_variables: + PASSWORD: "!@ESsdD323#sdu" + jobs: + one: + two: