Is it possible to run tasks/scripts within a job before a deployment job runs? I have an approval on the environment, which I want triggered by the deployment job, but it seems to want the approval before it runs job1 instead of running the tasks within job1 and then asking for approval before running the deployment job.
I want it to run all of the jobs within 'job1' and then ask for approval on the deployment job. Is this possible?
I have something similar to the below:
- stage: 1
variables:
- group: global
jobs:
- job: 'job1'
steps:
- task: DownloadPipelineArtifact@2
...
- task: ExtractFiles@1
...
- script: |
...
- deployment:
environment: DEV
strategy:
runOnce:
deploy:
steps:
- script: |
...
Unfortunately, no. The pre-process step within the pipeline run expands the templates and then evaluates all the dependencies within the pipeline before the pipeline executes. For example, the runtime determines if the pipeline has permission to use variable groups + service connections, or that the person executing the pipeline is allowed to consume those resources.
It does the same thing for each stage. Prior to execution, it evaluates the dependencies within the jobs and determines if Approvals or Checks are required. It bubbles these "checks" to the Stage. It would be fairly dangerous to start a stage and get halfway through the work only to realize the stage should never been executed in the first place.
It is important to note that "deployment" is a type of "job", and each job potentially runs on different agents, so downloading the artifacts to save time (which is what appears to be happening in your example) won't work as you've illustrated.
If you want to pause the execution of the pipeline mid-execution and wait for user-interaction there is the `Manual Validation Task' which can pause and wait for a user to click continue. This doesn't enforce who's allowed to click, but it notify a set of users that the task is waiting for their involvement. It's important to call out that this task is agentless: it doesn't run in your agent pool. A good reference example would be pausing before re-enabling traffic to a website (Traffic Manager, Deployment Slot, etc).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With