简体   繁体   中英

Azure DevOps pipeline yml shortcut possible?

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'

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 .

jobs:
  # track deployments on the environment
- deployment: DeployWeb
  displayName: deploy Web App
  pool:
    vmImage: ubuntu-latest
  # creates an environment if it doesn't exist
  environment: 'smarthotel-dev'
  strategy:
    # default deployment strategy, more coming...
    runOnce:
      deploy:
        steps:
        - script: echo my first deployment

I think you can't reduce those lines to get the powershell line without too much lines between. You could use other approaches. One I suggest is, based on official Microsoft documentation, you could use templates for your job to avoid those extra lines in your main yml.

Jobs templates

This solutions dosn't avoid you to write all those lines, but you probably will see more clear your main yml file and more readable.

Other approach is elevate steps line and his child lines, but it won't be referenced to deploy one, don't hace 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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM