Skip to content

Commit

Permalink
Merge pull request #123 from kritika-singh3/update-manual-approval
Browse files Browse the repository at this point in the history
Added support for allowOnlyOnSuccess in  manual approval
  • Loading branch information
tomzo authored Aug 21, 2019
2 parents b70892b + af84581 commit 903d8f7
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -78,10 +80,10 @@ public Map<String, Object> inverseTransform(Map<String, Object> 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<String, Object> yamlEnvVariables = environmentTransform.inverseTransform((List<Map<String, Object>>) stage.get(JSON_ENV_VAR_FIELD));
if (yamlEnvVariables != null && yamlEnvVariables.size() > 0)
stageData.putAll(yamlEnvVariables);
Expand Down Expand Up @@ -110,6 +112,7 @@ private void addInverseApproval(Map<String, Object> stageData, Map<String, Objec
return;

addRequiredValue(inverseApproval, approval, JSON_STAGE_APPROVAL_TYPE_FIELD, YAML_STAGE_APPROVAL_TYPE_FIELD);
addOptionalValue(inverseApproval, approval, JSON_STAGE_APPROVAL_ALLOW_ONLY_ON_SUCCESS_FIELD, YAML_STAGE_APPROVAL_ALLOW_ONLY_ON_SUCCESS_FIELD);
addOptionalList(inverseApproval, approval, JSON_STAGE_APPROVAL_ROLES_FIELD, YAML_STAGE_APPROVAL_ROLES_FIELD);
addOptionalList(inverseApproval, approval, JSON_STAGE_APPROVAL_USERS_FIELD, YAML_STAGE_APPROVAL_USERS_FIELD);

Expand All @@ -132,6 +135,7 @@ else if ("manual".equals(approval))
} else {
Map<String, Object> approvalMap = (Map<String, Object>) 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/examples/rich.gocd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 30 additions & 0 deletions src/test/resources/parts/stages/complete_with_manual_approval.json
Original file line number Diff line number Diff line change
@@ -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
]
}
18 changes: 18 additions & 0 deletions src/test/resources/parts/stages/complete_with_manual_approval.yaml
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit 903d8f7

Please sign in to comment.