In my repository, I have 2 PowerBi reports (.pbix files) in a folder:
In my Yaml pipeline, I am creating an artifact named "reports" and coping all the reports there in the CI step.
Then in the CD steps (Dev, Qa, and Prod), I am deploying them using PowerBIActions@5 task. Everything is working as expected. But I want to rename them in each environment.
For Example in DEV:
For Example in QA:
For Example in PROD:
This should be generic, in the future, I can have more reports. I have used copy files task but it does not have the option to provide the destination filename. There are other options like CmdLine ren, Powershell Rename-Item, and Powershell Copy-Item but they copy or rename a single file at a time. But in my case, there are 2 reports and the number of reports will increase in the future. So I do not want to put multiple Rename-Item tasks for each report. I think a loop or something else is required. Guidance will be appreciated.
Thanks.
The below code is a sample for 'Dev-'. You can capture the current environment and rename all of the '.pbix' files.
trigger:
- none
pool:
vmImage: ubuntu-latest
steps:
- script: |
dir
displayName: 'Run a multi-line script'
- task: PythonScript@0
inputs:
scriptSource: 'inline'
script: |
#foreach folder and rename files with specific suffix
import os
import re
def rename_files(path,env):
for file in os.listdir(path):
if file.endswith(".pbix"):
os.rename(file , env+file)
print(file)
print(os.path.join(path, file))
else:
pass
rename_files(".","Dev-")
- script: |
dir
displayName: 'Run a multi-line script'
Successfully on my side:
After rename the files, copy them to target place.