Bug 1311426 - [devexp_public_844]Cannot implement post-build command when adding Command with arguments to bc and build
[devexp_public_844]Cannot implement post-build command when adding Command wi...
Product: OpenShift Origin
Classification: Red Hat
Component: Build (Show other bugs)
Unspecified Unspecified
medium Severity medium
: ---
: ---
Assigned To: Rodolfo Carvalho
Wenjing Zheng
Depends On:
Blocks: 1311435
  Show dependency treegraph
Reported: 2016-02-24 03:50 EST by wewang
Modified: 2016-05-12 13:12 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1311435 (view as bug list)
Last Closed: 2016-05-12 13:12:59 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description wewang 2016-02-24 03:50:45 EST
Version-Release number of selected component (if applicable):
openshift v1.1.3-228-ge8dd2a2
kubernetes v1.2.0-alpha.7-703-gbc4550d
etcd 2.2.5

Description of problem:
Cannot implement post-build command when adding Command with arguments to bc and build

Steps to Reproduce:
1. Login to openshift and create project 
2. Create app
   $oc new-app -f https://raw.githubusercontent.com/openshift/origin/master/examples/sample-app/application-template-dockerbuild.json
3.  Add Command with arguments to bc and build
                "postCommit": {
                    "command": [
                    "args": [

   $oc start-build <bc>
4. Check the log 

Actual results:
4. I0224 08:02:36.952679       1 environment.go:31] DEPRECATED: Use .s2i/environment instead of .sti/environment
I0224 08:02:36.952721       1 environment.go:60] Setting 1 environment variables provided by environment file in sources
I0224 08:02:42.369979       1 common.go:134] Running post commit hook with image wewang/ruby-sample-build-7:70c11ead ...
sh: cannot set terminal process group (-1): Inappropriate ioctl for device
sh: no job control in this shell
rake aborted!
LoadError: cannot load such file -- sinatra/activerecord
/opt/app-root/src/config/database.rb:1:in `<top (required)>'
/opt/app-root/src/Rakefile:3:in `require_relative'
/opt/app-root/src/Rakefile:3:in `<top (required)>'
(See full trace by running task with --trace)
F0224 08:02:43.409992       1 builder.go:204] Error: build error: container "openshift_s2i-build_ruby-sample-build-7_wewang_post-commit" returned non-zero exit code: 1

Expected results:

Can implement Command with arguments  and image push to registry
Comment 1 wewang 2016-02-24 03:53:17 EST
when I use :
                "postCommit": {
                    "command": [
                    "args": [

build is complete ,but logs have error:
sh: cannot set terminal process group (-1): Inappropriate ioctl for device
sh: no job control in this shell

Comment 2 wewang 2016-02-24 03:56:34 EST
@rhcarvalho ,can you updated docs:https://github.com/PI-Victor/openshift-docs/blob/pi-victor/post_build_actions/dev_guide/builds.adoc#build-hooks? then merge

because I saw  post commit are not include "bundle exec";
        and command: ["/bin/sh", "-c"] should be command: ["/bin/sh", "-ic"] ,right?
Comment 3 wewang 2016-02-24 04:35:36 EST
when I updated bc below
 Add Command  to bc and build
                 "postCommit": {
                    "command": [

   $oc start-build <bc>
 Check the log 
Actual results:
 I0224 09:06:43.877799       1 common.go:134] Running post commit hook with image wewang/ruby-sample-build-10:59791539 ...
F0224 09:06:44.568459       1 builder.go:204] Error: build error: start container "openshift_s2i-build_ruby-sample-build-10_wewang_post-commit": API error (404): Cannot start container 62f8bad2d5b107a80b81396de4d4005b3e3e9ed515f71eb1071b8c7b4b9b7c96: [8] System error: exec: "bundle": executable file not found in $PATH
Comment 4 Rodolfo Carvalho 2016-02-24 06:42:56 EST
@wewang thanks for the report.

1. Docs

You are right, the docs need to be updated. I've asked Victor who is leading the PR, I would like to get it cleaned up today.

2. Syntax

There are multiple ways to run the tests if you are using the command/args syntax.

For example, you can use Bash (then no need for -i):
"command": ["/bin/bash", "-c", "bundle exec rake test"]

Or, alternatively (with the Ruby image, since this relies on the image entrypoint):
"args": ["bundle exec rake test"]

(I'm updating the sample-app to use this as example, see https://github.com/openshift/origin/pull/7567)

I will comment on the values you tried to use and why they didn't work:

                "postCommit": {
                    "command": ["/bin/sh", "-ic"],
                    "args": ["rake", "test"]

This doesn't work because "rake" and "test" are passed as separate arguments, so only "rake" is executed and it fails ("rake aborted!"), the "test" part is ignored.


$ /bin/sh -ic "echo 123" this will be ignored

The example above, written with the command/args syntax is:
"command": ["/bin/sh", "-ic", "echo 123", "this", "will", "be", "ignored"]

Notice that command + args is the same as having only command with empty value for args, IOW:

{"command": ["/bin/bash"], "args": ["/my/script"]} == {"command": ["/bin/bash", "/my/script"]}

                "postCommit": {
                    "command": ["/bin/sh", "-ic"],
                    "args": ["bundle", "exec", "rake", "test"]

Same problem with args, should be a single string:

{"command": ["/bin/sh", "-ic"], "args": ["bundle exec rake test"]}

                 "postCommit": {
                    "command": ["bundle", "exec", "rake", "test", "--verbose"]

In this case, the Ruby image doesn't have "bundle" in the PATH by default ('"bundle": executable file not found in $PATH').
That's a known limitation of our SCL images, that need the appropriate SCLs to be enabled before you can use them.
We try to make it better by automatically enabling collections when:
   i.  `/bin/bash` is used
   ii. `/bin/sh -ic` is used

In all other cases, `scl enable ruby200` (depends on exact version) is needed.

That's why the script syntax uses `/bin/sh -ic`.

I didn't try, but something like this should work as well:

{"command": ["scl", "enable", "ruby200", "bundle", "exec", "rake", "test", "--verbose"]}

(might be missing something or have wrong collection name)
Comment 5 wewang 2016-02-25 02:02:28 EST
@ Rodolfo Carvalho thanks for your detail comments
I already see docs has been updated 

and verified below sceniaros , it all works 
verified version:
openshift v1.1.3-271-g28e5bbf-dirty
kubernetes v1.2.0-alpha.7-703-gbc4550d
etcd 2.2.5

a.b.  updated postCommit with command and args 
       command: ["bundle", "exec", "rake", "test"]
       args: ["--verbose"]

c.  updated postCommit with command, "bundle exec rake test --verbose" is a single args :
      command: ["/bin/bash", "-c", "bundle exec rake test --verbose"]
the bug already verified now, you can set the bug to assigned,   if docs pr is merged ,will accept related card ,thanks for your quick response.
Comment 6 wewang 2016-02-25 20:34:48 EST
as comment5 , and  verified in ose32 :openshift v3.1.1.906 too.

Note You need to log in before you can comment on or make changes to this bug.