1
votes

I am compiling my c++ code. My requirement is to generate artifacts with two file. 1: Binary file 2: Readme file I am able to generate a binary file, but I am unable to generate a readme file in a specific format. Readme file contains build number in below format buildnumber = $a.$d.$e $a= build pipeline variable that can be set , $d =some incremental value, $e =git commit SHA like 669b7f8e

I don't want to use power shell “##vso[build.updatebuildnumber]build number”and put value.

my pipeline is :

    variables:
      - name: Version
        value: 1
      - name: VersionRevision
        value: $[counter(variables['Version'], 0)]
      - name: commitsha
        value: $['Build.SourceVersion']
      - name: build
        value: mybuild
      - name: buildnumber
        value: $[ format('{0}.{1}.{2}', variables['build'], variables['VersionRevision'],variables['commitsha']) ]

trigger:
- master

jobs:
- job: gcctest
  pool:
   vmImage: 'ubuntu-16.04'
  steps:
  - script: sudo apt-get update && sudo apt-get install libboost-all-dev
  - script: g++ -std=c++11 -I/usr/include/boost/asio -I/usr/include/boost -o result.out m.cpp
          c.cpp d.cpp f.cpp 

  - bash: echo $(buildnumber)>test.txt
  - task: CopyFiles@2
    inputs:
      sourceFolder: '$(Build.SourcesDirectory)'
      contents: '?(*.out|*.txt)'
      targetFolder: $(Build.ArtifactStagingDirectory)
  - task: PublishBuildArtifacts@1
    inputs:
        pathToPublish: $(Build.ArtifactStagingDirectory)
        artifactName: result
1
Why you don't want to use a powershell script? The inline version would do that easily for you.Mar Tin
Thanks, @MarTin, I am coming from bash background, I don't have much idea of PowerShell, would you edit my script, where I need to change. Also, a challenge is that I want the first 8 characters of commit hash in the readme file. I don't know how to do that.Vijay Verma
When you have the SHA1 in a variable as a string use $sha.substring(0,8) to get the first 8 chars of the commit id.Josh Gust

1 Answers

0
votes

Put that inside on a inline PowerShell script task:

$text = "$($build).$($VersionRevision).$($commitsha)"
Write-Host $text -ForegroundColor Yellow
$text > "readme.txt"

PowerShell Script Task

Keep in mind that you have to define $build, $VersionRevision and $commitsha before or you add the definition inside of the PowerShell script.