title: Azure Devops - not able to set variable in Powershell
body: <p>I have an Azure Devops release pipeline (using the Classic Editor rather than yaml) and am having trouble setting a variable in an inline powershell script. The relevant part of the script is this:</p>
  <pre><code>Write-Host &quot;Web is $web&quot;
  Write-Host &quot;App is $app&quot;
  
  Write-Host &quot;##vso[task.setvariable variable=MyWebEnv;]$web&quot;
  Write-Host &quot;Set Web to $($MyWebEnv)&quot;
  
  Write-Host &quot;##vso[task.setvariable variable=MyAppEnv;]$app&quot;
  Write-Host &quot;Set App to $(MyAppEnv)&quot; 
  </code></pre>
  <p>The log files indicate that my <code>$web</code> and <code>$app</code> variables hold the correct values, however the setting is not working.</p>
  <p>I've tried writing out the value in both the <code>$($env:MyWebEnv)</code> and <code>$(MyWebEnv)</code> formats and both formats indicate that the ADO variable has not been set correctly.</p>
  <p>My variable is defined in the variables tab on the pipeline. It is set to Settable at queue time. I have tried with no value set in the definition and an initial value and I can see that the initial value does not get overwritten.</p>
  <p>I've tried running this on both a self-hosted agent and an Azure Pipelines Hosted agent - same results. I have another release pipeline that does something similar without issues.</p>
  <p>I'm trying to use the variable in a subsequent Stage.</p>
  <p>I don't want to write the variable to a file or anything as I want to use the variable to control whether the stage even runs.</p>
  <p>Edit:
  Based on Levi's comment I tried adding <code>isOutput=true</code> and inspecting the variable in a subsequent step in the same stage - it's not visible even within a subsequent step:</p>
  <p><a href="https://i.stack.imgur.com/xq8qI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xq8qI.jpg" alt="pipeline output" /></a></p>
  <p>=========================================================================
  Edit 2:
  I must have had a non visible character somewhere. I was composing the powershell in an external editor  (just so I had more space) and pasting into the inline textbox in ADO - when I typed in the exact same thing I had into the editor it started working - sort of.</p>
  <p>I can set the variable now and it's appearing in the task below, but what I really want is to use it in the next stages - in the IIS deployment group to control that IIS server A runs, but IIS server B doesn't. I'm attempting to do this in the Additional Options Run Expression.</p>
  <p>I've tried
  <code>and(succeeded(), eq(variables['MyWebEnv'], 'myvalue')</code></p>
  <p>or (where MyOutput. is the name given to my output reference when setting the variable)
  <code>and(succeeded(), eq(variables['MyOutpub.MyWebEnv'], 'myvalue')</code>
  or
  <code>and(succeeded(), eq(variables['MyOutpub_MyWebEnv'], 'myvalue')</code></p>
  <p>To clarify, I'm doing this on the IIS Deployment Group itself, and not on any of the tasks within that group.</p>
  <p>I keep seeing that the deployment is skipped due to:
  <code>Evaluating: eq(variables['MyOutput,MyWebEnv'], 'myvalue') Expanded: eq(Null, 'myvalue') Result: False</code></p>