Monday 15 August 2011

ruby - Chef bash execute not_if some command returns 1 -


I need a checkout code git repo & amp; If the code is the wrong branch in the Repo DIR, then only mvn clean package . How can I do this with a chef recipe (or without)?

  bash "checkout_and_compile_if_wrong_version" user "development" group "development" cwd "/ var / www /" environment 'HOME' = & gt; "/ Home / develop" code & lt; & Lt; -EOH CD / var / www / code_repo / git checkout # {node ['last_version']} git pull mvn clean package eoh not_if {... condition ...} end  

I can use some kind of investigation (in code_repo dir):

  ["$ (git branch | grep" * * | | awk '{print $ 2}') ) "== # {node ['last_version']}] & amp; Amp; Thx in advance   is obviously better suited for your use.  

I will do something like this (untested code):

  executed "clean package" cwd "/ var / www / code_repo" / "command" mvn clean package " User "developed" group "development" verb: nothing end GIT "/ var / www / code_repo /" repository "you_repo_url" revision node ['last_version'] user "development" group "development"  

This will sync if a new one is committed or if the node ['last_version'] / code> changes and runs mvn clean only when there is a change Home env var Git is set by resource, so there is no need to provide it.


Edit per comment:

Not_if or Only_if Before any guard document:

A string is executed as a shell command. If the command returns 0, the guard is applied. If the command Gives another value, then the guard attribute is not applied

the recipe code:

  bash "whatev Er "command" test "only_of% cue {git branch | Awk '/ ^ [*] / {exit $ 2 == "# {node [' last_version ']}"}'} ,: cwd = & gt; "/ Var / www / code_repo" and  

Tripe Part: Bash will work only if the version is not equal to node ['last_version'] (<0 >

I simplified the grep / awk / test part to a single AVP script which starts with * ( / / ) and then the second The code is telling awk to go out of the result of comparison between the field (real GIT branch) and chef attribute version. % Q {code and "quote test indide"} using quotation marksThere is a Ruby form to allow for gram.

If the comparison is correct, do not do anything, if it is wrong, run the Bash script.

If so, try to use Maharaj's resources and as much as possible with shave resources (periodically idempotent is easy to maintain and maintain)


No comments:

Post a Comment