0

I invoke a saltstack state file "init.sls" from a Jenkins pipeline as below. If job == Yes, it is expected to execute test_command and test_final, else if job == No, it must execute test2_command and test_final

{% if {{ job }} == 'Yes' %}
test_command:
  cmd.run:
    - name: echo "TEST COMMAND EXEC"
{% elif {{ job }} == 'No' %}
test2_command:
  cmd.run:
    - name: echo "TEST2 COMMAND EXEC"
{% endif %}

test_final:
  cmd.run:
    - name: echo "FINAL SUCCESS"

However it is not successful. Is there a better way to achieve using salt state execution?

  • You may want to describe what is not successful means. – Dan Cornilescu Apr 18 at 1:52
  • [Pipeline] Data failed to compile: ---------- Rendering SLS 'base:projects.test' failed: Jinja syntax error: expected token ':', got '}'; line 4 --- {% if {{ job }} == 'Yes' %} <====================== test_command: cmd.run: - name: echo \"TEST IF COMMAND EXEC\" {% elif {{ job }} == 'No' %} dpio_command: [...] ---"}}] [Pipeline] } – Narasimha Apr 18 at 4:30
0

The jinja syntax error is caused by the {{ around your job var. Those curly braces are not required as you are already inside jinja block, noted by the {%.

So to get your code working just replace your {{ job }} by job. This should be working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.