I added if statement in my code to do something and because of some specific reason I had to add the same if content after if statement like the following:
if ("something") {
version = sh(script: "yq read -j override_service.yaml | jq -r "something"
}
version = sh(script: "yq read -j environments/${ENV}/service.yaml | jq -r "something"
note: in above sample of code, parts "something" are exactly the same for both version part inside and outside of if.
and also the contents of the file override_service.yaml which exist in if statement and service.yaml outside if are the same, just in the second script it will read the file with environment variable
problem: if content is useless because I define the variable version that is immediately overridden outside the if, before it is used
possible solution: I should eliminate if statement and use only one command and add the file name (override_service.yaml) in the command outside of if block as a variable.
how I can do that?
Aucun commentaire:
Enregistrer un commentaire