Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exit code flag #77

Merged
merged 5 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ steps:
environment:
CGO_ENABLED: 0

- name: release-docker-dev
image: plugins/docker
settings:
build_args_from_env:
- BUILD_DATE
- DOCKERFILE_PATH
- VCS_REF
- VERSION
dockerfile: docker/Dockerfile.linux.386
environment:
- "BUILD_DATE=$(date -u +\"%Y-%m-%dT%H:%M:%S%Z\")"
- "DOCKERFILE_PATH=\"/docker/Dockerfile.linux.386\""
- VCS_REF=$(git rev-parse --short HEAD)
- VERSION=$(git describe --always --tags --dirty)
password:
from_secret: docker_password
repo: meltwater/drone-cache
tags: dev
username:
from_secret: docker_username

- name: rebuild-cache
pull: true
image: meltwater/drone-cache:dev
Expand All @@ -62,6 +83,7 @@ steps:
region: eu-west-1
path_style: true
endpoint: filestorage:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Expand All @@ -78,6 +100,7 @@ steps:
region: eu-west-1
path_style: true
endpoint: filestorage:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Expand All @@ -95,6 +118,7 @@ steps:
region: eu-west-1
path_style: true
endpoint: filestorage:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Expand All @@ -109,6 +133,7 @@ steps:
mount:
- vendor
rebuild: true
exit_code: true
volumes:
- name: cache
path: /tmp/cache
Expand Down Expand Up @@ -166,6 +191,7 @@ steps:
restore: true
path_style: true
endpoint: filestorage:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Expand All @@ -183,6 +209,7 @@ steps:
restore: true
path_style: true
endpoint: filestorage:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Expand All @@ -197,6 +224,7 @@ steps:
mount:
- vendor
restore: true
exit_code: true
volumes:
- name: cache
path: /tmp/cache
Expand All @@ -219,6 +247,7 @@ steps:
restore: true
path_style: true
endpoint: filestorage:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Expand Down
19 changes: 18 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ func main() {
Usage: "debug",
EnvVar: "PLUGIN_DEBUG, DEBUG",
},
cli.BoolFlag{
Name: "exit-code, ex",
Usage: "always exit with exit code, disable silent fails for known errors",
Hidden: true,
EnvVar: "PLUGIN_EXIT_CODE, EXIT_CODE",
},

// Volume specific Config args

Expand Down Expand Up @@ -319,7 +325,7 @@ func main() {
EnvVar: "SFTP_HOST",
},
cli.StringFlag{
Name: "sftp-host",
Name: "sftp-port",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the reviewer: This minor issue has introduced by the previous PR.

Usage: "sftp port",
EnvVar: "SFTP_PORT",
},
Expand Down Expand Up @@ -405,10 +411,21 @@ func run(c *cli.Context) error {
}

err := plg.Exec()
if err == nil {
return nil
}

if c.Bool("exit-code") {
// If it is exit-code enabled, always exit with error
log.Println("silent fails disabled, exiting with status code on error")
return err
}

if _, ok := err.(plugin.Error); ok {
// If it is an expected error log it, handle it gracefully
log.Println(err)
return nil
}

return err
}