Add condition to task queries
Asked by Abhishek kaushik:

Can you please help me with one of the queries.

I have a task running some powershell script. There is a variable being used inside the script and its value is coming out to be 0 or 1.

Basis on this variable output within the script, I need to do source checkout (another task) depending on "Add condition to task ".

I tried bamboo inject variable method but its not helping either as this will not work with injected variables, but only with plan or global ones


Answers:
author: Eduardo Alvarenga
body: Hello [@Abhishek kaushik](/t5/user/viewprofilepage/user-id/3991401)

Task conditioners work normally with Injected variables. Can you demonstrate how you are exporting, importing and consuming those variables?

Exported variables will derive from a Java properties format *key=value*. Eg.

1. On a script task, create a variables.txt file with "***go=yes**"*
2. Add an *Inject Bamboo Variables* task and load that file. Se the namespace as "**atlas**" (example)
3. On the task you wish to add the Conditional, select:
   1. Add a condition to task
   2. Variable ***atlas.go** = yes*
4. If the injected variable "**atlas.go**" = yes then the Task on #3 will run.

Best regards,

Eduardo Alvarenga  
Atlassian Support APAC

**--please don't forget to Accept the answer if the reply is helpful--**

comments: author: Abhishek kaushik
body: Hi [@Eduardo Alvarenga](/t5/user/viewprofilepage/user-id/4365410) ,

I tried the similar steps but the source code checkout is not getting triggered as in the logs as it says "skipping task because of unfulfilled condition."

One thing i noticed is there are some weird special characters showing in the logs, is this expected or happening because of file formatting. I am doing echo "EXITCODE=$LASTEXITCODE" \> EXITCODE.txt) in my powershell script

```
Injected variable bamboo.exitcodeinject.??E?X?I?T?C?O?D?E?=?0? in LOCAL scope
```

```
Injected variable bamboo.exitcodeinject.?= in LOCAL scope
```


author: Eduardo Alvarenga
body: Hello [@Abhishek kaushik](/t5/user/viewprofilepage/user-id/3991401)

This is a well-known issue with character encoding on Windows Please check this bug for a workaround:

* [BAM-21898 - Inject Bamboo Variable on Windows script task has an encoding issue](https://jira.atlassian.com/browse/BAM-21898)

I recommend you mark yourself as affected and also watch that bug to be notified when the final fix is implemented.

Best regards,

Eduardo Alvarenga  
Atlassian Support APAC

**--please don't forget to Accept the answer if the reply is helpful--**


author: Abhishek kaushik
body: Thanks [@Eduardo Alvarenga](/t5/user/viewprofilepage/user-id/4365410)

I was able to do the source code checkout basis on above. However, UTF-8 was still showing weird special characters but when converted to ascii, it fixed everything. Here is my fix

echo EXITCODE=$LASTEXITCODE \| Out-File -FilePath \<File location with filename\> -Encoding ascii


author: Eduardo Alvarenga
body: Good job [@Abhishek kaushik](/t5/user/viewprofilepage/user-id/3991401)!

Make sure to *Accept* the solution provided if you were able to get the issue sorted.

Eduardo Alvarenga  
Atlassian Support APAC