Reputation: 537
I have a pipeline exporting Azure boards work items to csv file.
Here is the process:
Download the build artifact(csv file and timestamp.txt) from the last successful pipeline run.
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.
Publish the updated or "un-updated" csv file and timestamp.txt as build artifacts.
Upload the updated csv file to SharePoint site.
What I want to implement:
Whether csv file is updated or not, the pipeline run should end as successful.
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).
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'
Upvotes: 2
Views: 1691
Reputation: 41745
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'))
Upvotes: 2