I saw on some resource that you can write shortcuts in yml code but I don’t remember where I saw it or how I would look that up now.
The code below seems like a lot of almost empty lines before you get to the PowerShell script. Is there a way to condense that so PowerShell won’t be so indented?
- stage: B
dependsOn: []
jobs:
- deployment: B1
displayName: Test Job
environment: rodney-test-env
strategy:
runOnce:
deploy:
steps:
- powershell: |
'hello world'
2
Answers
You need to follow the YAML schema in Azure Pipeline, so it is not supported to condense the PowerShell task in your example.
You could refer to the below example shown on the official doc.
I think you can’t reduce those lines to get the powershell line without too much lines in between. You could use other approaches. One I suggest is, based on official Microsoft documentation, the use of job templates. This avoid those extra lines in your main yml. This solution doesn’t avoid you to write all those "blank" lines, but you probably will see more clear your main yml file and more readable.
Jobs templates
Other approach is elevate steps line and his child lines, but it won’t be referenced to the deploy line, I don’t have enough context for that, so you should evaluate it.
Another way, not recommended, could be to use the dependOn property to set those lines in separate steps/jobs to keep the main job as clear, but this approach is not good practice for that purpose, you should not take this way…