title: Cannot delete release pipeline as it is currently 'deployed on stage' error
body: <p>I have a pipeline that has a &quot;Setup&quot; stage that is run automatically as soon as the release is created:</p>
  <p>This is accomplished using a stage with the &quot;After release&quot; trigger:</p>
  <p><a href="https://i.stack.imgur.com/1Lix0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1Lix0.png" alt="enter image description here" /></a></p>
  <p>All other stages (deployments to physical locations) must only be run manually as and when the deployment to that environment is approved (i.e. cannot be set up to trigger automatically)</p>
  <p>Unfortunately, use of a &quot;stage&quot; to do release pipeline setup means that if we create a release, but decide not to deploy the release and instead delete it, DevOps complains that it &quot;cannot be deleted as it is currently deployed on stage(s) Setup.&quot;.</p>
  <p><a href="https://i.stack.imgur.com/VzI1G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VzI1G.png" alt="enter image description here" /></a></p>
  <p>The point of the &quot;Setup&quot; phase is that it runs some mildly complex powershell in order to auto-determine the correct name of the release via the log command:</p>
  <pre><code>Write-Host &quot;##vso[release.updatereleasename]$releaseName&quot;
  </code></pre>
  <p>I cannot simply re-run the setup stage of a prior release because the date of release creation is a component of the release name, and rerunning the setup stage would alter the name to the current date. (In fact, if anyone knows how to disable re-running a stage as a bonus, I'd love to hear it.)</p>
  <p>For context (to justify the need of a &quot;Setup&quot; stage) - The powershell I'm using derives the desired release name from some complex rules regarding the source build branch / tag name - something which cannot be accomplished using the simple built-in &quot;Release name format&quot; option or environment variables as far as I know. Here's the logic:</p>
  <pre><code>$releaseId = &quot;$(Release-Id)&quot;
  if( $releaseId -ne &quot;(automatic)&quot; ) {
      Write-Host &quot;Release id has been overridden by the creator to '$releaseId'.&quot;
      return
  }
  Write-Host &quot;Auto-determining the release id...&quot;
  
  $sourceBranch = &quot;$(Build.SourceBranch)&quot;
  if($sourceBranch.StartsWith(&quot;refs/tags/&quot;)) {
      Write-Host &quot;Tag deployment detected. Release Id should match the tag name.&quot;
     $releaseId = &quot;v. $(Build.SourceBranchName)&quot;
  } elseif($sourceBranch.EndsWith(&quot;merge&quot;)) {
      Write-Host &quot;Pull Request build deployment detected. Release Id will include the pull request branch name and SHA.&quot;
     $sha = &quot;$(Build.SourceVersion)&quot;.Substring(0, 7)
     $releaseId = &quot;PR $(Build.SourceBranchName) $sha&quot;
  } elseif($sourceBranch.StartsWith(&quot;refs/heads/&quot;)) {
      Write-Host &quot;Branch build deployment detected. Release Id will include branch name and SHA.&quot;
     $sha = &quot;$(Build.SourceVersion)&quot;.Substring(0, 7)
     $trunc = &quot;$(Build.SourceBranchName)&quot;
     $trunc = If ($trunc.Length -gt 33) { $trunc.Substring(0, 30) + &quot;...&quot; } else { $trunc }
     $releaseId = &quot;Branch $trunc $sha&quot;
  } else {
      Write-Host &quot;Unrecognized source branch syntax '${sourceBranch}'. Release number will match build number.&quot;
     $releaseId = &quot;$(Build.BuildNumber)&quot;
  }
  
  # Retain the default release name configured in Options and just replace the default release id
  $releaseName = &quot;$(Release.ReleaseName)&quot;.Replace(&quot;(automatic)&quot;, $releaseId)
  Write-Host &quot;Setting the id of the release to '$releaseName'.&quot;
  Write-Host &quot;##vso[release.updatereleasename]$releaseName&quot;
  </code></pre>
  <p>As far as I'm aware, DevOps Release Pipelines offer no way to execute code such as this automatically on each creation of a release without creating a &quot;stage&quot; that is configured to run on release. Unfortunately, there seems to be no way to treat a &quot;stage&quot; as just a pipeline step - there seems to be an assumption that each stage must represent a physical environment or something.</p>
  <p>Aside from the minor inconvenience of being unable to delete the latest release, I'm exceeding pleased with the experience of being able to code the automatic construction of complex release names in this way, and am only seeking solutions that don't sacrifice this feature.</p>
  <p>Does anyone have any suggestions or know of any workarounds?</p>