2

I have a pipeline exporting Azure boards work items to csv file.

Here is the process:

  1. Download the build artifact(csv file and timestamp.txt) from the last successful pipeline run.

  2. Run a Python script to query work items updated since last successful pipeline run(last export time is in timestamp.txt). If there are updated work items, then update csv file with these work items, update the timestamp.txt and exit program with 0. If no updated work items found, exit program with a non-zero value.

  3. Publish the updated or "un-updated" csv file and timestamp.txt as build artifacts.

  4. Upload the updated csv file to SharePoint site.

What I want to implement:

  1. Whether csv file is updated or not, the pipeline run should end as successful.

  2. I need to define a bool variable that can be set depends on the exit code of Python script(or it can be directly set in the Python script).

  3. Use that bool variable as condition for the upload-to-SharePoint task.

How to create the YAML file to implement this? Thanks.

YAML:

# - master
trigger: none

schedules:
- cron: "0 */12 * * 1,2,3,4,5"
  displayName: Hourly Azure All WorkItems Export
  branches:
    include:
    - master
  always: true
   
pool: 'Windows-VS2017DEV'


steps:

# - task: InstallPython@1
#   inputs:
#     version: 'python'

- task: UsePythonVersion@0
  inputs:
    versionSpec: '3.x'
    addToPath: true
    architecture: 'x64'

- task: DownloadBuildArtifacts@0
  inputs:
    buildType: 'specific'
    project: 'XXX'
    pipeline: 'xxx'
    buildVersionToDownload: 'latest'
    downloadType: 'single'
    artifactName: 'Azure_Reporting'
    downloadPath: '$(System.DefaultWorkingDirectory)'


- task: PythonScript@0
  inputs:
    scriptSource: 'filePath'
    scriptPath: 'Python/azure_workitems.py'
    arguments: '$(azure_workitems_option)'   

- task: CopyFiles@2
  inputs:
    contents: |
      *csv
      timestamp.txt
    targetFolder: $(Build.ArtifactStagingDirectory)
    
- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: $(Build.ArtifactStagingDirectory)
    artifactName: Azure_Reporting

- task: UploadFilesToSPDocLib@1
  inputs:
    spUrl: 'https://XXXX.sharepoint.com/sites/XXXX'
    targetFolder: 'Shared%20Documents/Status%20dashboards/Azure_Reporting'
    login: '[email protected]'
    password: $(XXX.Credential)
    filesToUpload: ' $(Build.ArtifactStagingDirectory)/azure_workitems.csv'

1 Answer 1

2

Inside the python script you can assign a new variable with the value according to your logic (instead of exit code).

For example, if the code did what he should and you want to run the upload-to-SharePoint task, add the following logging command:

print('##vso[task.setvariable variable=uploadSP]true')

And in the upload-to-SharePoint task add a custom condition:

and(succeeded(), eq(variables['uploadSP'], 'true'))
Sign up to request clarification or add additional context in comments.

1 Comment

shouldn't one set a name for the task and add writeOutput:true to the print statement, then state: and(succeeded(), eq(variables['taskName.uploadSP'], 'true'))?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.