docker-buildkite-plugin icon indicating copy to clipboard operation
docker-buildkite-plugin copied to clipboard

redirection via `>` is not possible

Open joscha opened this issue 5 years ago • 3 comments

e.g.: I can't disable quoting even though the command option of the docker plugin should allow me to pass things verbatim.

A step like this:

  - label: ':bash: Lint: SH'
    command: ''
    artifact_paths:
      - web/target/shellcheck-*.xml
    plugins:
      - 'docker#v3.3.0':
          image: 'koalaman/shellcheck:v0.7.0'
          debug: false
          workdir: /workdir
          command:
            - '-x'
            - a.sh
            - '--format'
            - checkstyle
            - '>'
            - web/target/shellcheck-42820572-83ee-4588-abf2-4f761754dba9.xml

results in:

koalaman/shellcheck:v0.7.0 -x x.sh --format checkstyle \> web/target/shellcheck-42820572-83ee-4588-abf2-4f761754dba9.xml

which means the output of the docker image is not redirected and thus not picked up as an artifact.

joscha avatar Oct 30 '19 13:10 joscha

This is not specific to shellcheck but to any docker image - just in case you want to suggest using https://github.com/buildkite-plugins/shellcheck-buildkite-plugin for this particular problem: it also can't redirect the output and shellcheck doesn't have a first-class --out my.file flag either.

joscha avatar Oct 30 '19 13:10 joscha

I reckon this is probably outside the scope of what the docker plugin is supposed to do 🤔

I'd be happy to add support to the shellcheck plugin to write to a file? Alternately, perhaps it's easier to just call docker directly in a shellscript for this usecase?

lox avatar Nov 01 '19 03:11 lox

I can definitely write a wrapper or something, but I think output redirection would be a responsibility of the plugin?

joscha avatar Nov 01 '19 04:11 joscha

From what I can see, this would be expected (albeit quite annoying) behaviour.

The command docker run ... image arg1 arg2 arg3 > output_file would redirect the output of the docker command, not what is run inside of the container itself. As you are clearly specifying that the redirection character is part of the docker command, it needs to be escaped or it wouldn't be passed on to the command running in the container... which will error out or ignore it. This is mostly because output redirection is a feature of terminal shells, not docker nor the programs run in them.

The way to workaround this issue is to use a shell as the command being executed. For example:

- label: ':bash: Lint: SH'
    command: ''
    artifact_paths:
      - web/target/shellcheck-*.xml
    plugins:
      - 'docker#v3.3.0':
          image: 'koalaman/shellcheck:v0.7.0'
          command:
            - '/bin/sh'
            - '-c'
            - 'shellcheck -x a.sh --format checkstyle > web/target/shellcheck-42820572-83ee-4588-abf2-4f761754dba9.xml'

Which is exactly what happens when you specify the command to be run through the step's command instead of the plugin's command option:

- label: ':bash: Lint: SH'
    command: 'shellcheck -x a.sh --format checkstyle > web/target/shellcheck-42820572-83ee-4588-abf2-4f761754dba9.xml'
    artifact_paths:
      - web/target/shellcheck-*.xml
    plugins:
      - 'docker#v3.3.0':
          image: 'koalaman/shellcheck:v0.7.0'

Note that this assumes that the image you are using is not forcing a particular executable through entrypoints (in which case you may have to override it)

toote avatar Sep 19 '22 23:09 toote

I believe there is nothing wrong with the plugin so I am closing this issue. Feel free to reply if you think it shouldn't have and we'll re-open it and continue the discussion

toote avatar Sep 19 '22 23:09 toote