0

this is developer repo pipeline

resources:
  repositories:
  - repository: extendCheck
    type: git
    name: PUL/extendCheck

trigger:
- none

extends:
  template: base2.yml@extendCheck
  parameters:
    buildSteps:  
      - bash: echo Test #Passes
        displayName: succeed
      - bash: echo "Test"
        displayName: succeed
      - script: echo "Script Test" 
        displayName: Fail

this is extend template from centralized policy team's repo

# File: start.yml
name: $(Date:yyyy)$(Date:.MM)$(Date:.dd)$(Rev:-r)
parameters:
- name: buildSteps # the name of the parameter is buildSteps
  type: stepList # data type is StepList
  default: [] # default value of buildSteps
stages:
- stage: secure_buildstage
  pool:
    vmImage: 'ubuntu-latest'
  jobs:
  - job: secure_buildjob
    steps:

    - script: echo This happens before code 
      displayName: 'Base: Pre-build'

    - script: echo Building
      displayName: 'Base: Build'

    - ${{ each step in parameters.buildSteps }}:
      - ${{ each pair in step }}:
          ${{ if ne(pair.key, 'script') }}:
            ${{ pair.key }}: ${{ pair.value }}       
          ${{ if eq(pair.key, 'script') }}: # checks for buildStep with script
            'Rejecting Script: ${{ pair.value }}': error # rejects buildStep when script is found         

    - script: echo This happens after code
      displayName: 'Base: Signing'

When i run this , i get following error

/base2.yml@extendCheck (Line: 2, Col: 1): Unexpected value 'name'

We want to control the build number format and so don't want to keep it in developer repo. Any suggestions for this problem

Sanjeev
  • 415
  • 5
  • 17

1 Answers1

0

Unfortunately, it is not supported using a template for name. To work around this issue, we can use a script to define the variable and use the UpdateBuildNumber command to update the build numbering format. For example, add the following task in the end of base2.yml file:

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      [string] $dateTime = (Get-Date -Format 'yyyyMMddTHHmmss')
      Write-Host "##vso[task.setvariable variable=name]$dateTime"  
- script: echo "##vso[build.updatebuildnumber]$(name)"
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • how can i use this $(Date:yyyy)$(Date:.MM)$(Date:.dd)$(Rev:-r) as format in powershell? – Sanjeev Jul 29 '20 at 19:20
  • Specially (Rev:-r) , the purpose of using this in extend template is to ensure we don't go by user specified name but generate standard build name using above format. if they update the name in their repo the revision value would be different. – Sanjeev Jul 29 '20 at 19:40
  • In Azure DevOps `Rev` is a special variable format that only works in the Build Number field. You could use `$(Build.BuildNumber)` or the `counter()` expression instead. Check blog here: https://www.andrewhoefling.com/Blog/Post/azure-pipelines-custom-build-numbers-in-yaml-templates – Cece Dong - MSFT Jul 30 '20 at 02:17