tfsazure-devopsoctopus-deployoctopus

TFS build step `Promote Project in Octopus` - variable for invoking build step if invoked by specific user


I'm trying to setup CD to staging for one of our apps. I have it set up to do the following:

  1. merge to master causes TFS Build and autodeploys to devlab
  2. build step kicks off e2e tests in tfs and runs tests against devlab
  3. IF e2e tests pass, I want to promote the build to staging then i'll repeat the steps (stopping short of auto-deploy to prod)

here's where I'm encountering my issue:

I've got a build step on the e2e test build called "promote project to octopus" - this build also runs on a scheduled cadence (nightly), so I only want the last step (promote project to octopus) IF the user who kicked off the test is octopus-user (it's the name we gave the bot).

using this as a resource: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml#examples

on the 'custom condition" of this build step, i've tried several different variables using the guidance provided in the link above. Here are 2 examples:

and(succeeded(),equals(variables['Build.RequestedBy],'octopus-user'))

and(succeeded(), equals(variables['Build.RequestedFor'], 'octopus-user'))

IF I remove this variable the build succeeds and promotes the build to staging, as expected. When I insert the variable/s I get different failures, anyone have guidance on how to set a variable to kick off if it's for kicked off by a specific user? (in this case octopus-user) - could the issue be the format of the username, perhaps it needs to be the email address (though I've tried that, as well as the AD credentials for the user).


Solution

  • Conditions are written as expressions. The agent evaluates the expression beginning with the innermost function and works its way out. The final result is a boolean value that determines if the task, job, or stage should run or not. See the Expressions topic for a full guide to the syntax.

    Depending on the execution context, different variables are available.

    According to your description, if you want to use E-mail address, please use Build.RequestedForEmail instead of Build.RequestedFor.

    And if your name/value contain a whitespace, See "How are the identity variables set?".

    Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail.