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

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

CC BY-SA 4.0
2019-06-12T12:59:25.417Z
2019-06-12T12:59:25.417Z
Pier
<p>I invoke a saltstack state file "init.sls" from a Jenkins pipeline as below. If <code>job == Yes</code>, it is expected to execute <code>test_command</code> and test_final, else <code>if job == No</code>, it must execute <code>test2_command</code> and <code>test_final</code></p>

<pre><code>{% 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"
</code></pre>

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

CC BY-SA 4.0
2019-04-18T01:52:59.703Z
You may want to describe what `is not successful` means.
Dan Cornilescu
CC BY-SA 4.0
2019-04-18T04:30:01.307Z
[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
<salt>
Why is IF failing with satl state file from Jenkins?
Narasimha
# Why is IF failing with satl state file from Jenkins?

(Asked by: username_0 on 2019-04-17)

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?

**Tags:** salt

> **Comments:**
> **username_1**: You may want to describe what `is not successful` means.  
> **username_0**: [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] }  

---

## 1 answers

### Answer by username_2 on 2019-06-12. Score: 1

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.


---

