PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 9, 2022

[FIXED] How to rename multiple PowerBi reports in Dev, QA, PROD during CICD using Azure DevOps Yaml Pipeline?

 October 09, 2022     azure-devops, azure-pipelines, cicd, continuous-integration, powerbi     No comments   

Issue

In my repository, I have 2 PowerBi reports (.pbix files) in a folder:

  • Report1.pbix
  • Report2.pbix

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:

  • DEV - Report1.pbix
  • DEV - Report2.pbix

For Example in QA:

  • QA - Report1.pbix
  • QA - Report2.pbix

For Example in PROD:

  • PROD - Report1.pbix
  • PROD - Report2.pbix

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.


Solution

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:

enter image description here

After rename the files, copy them to target place.



Answered By - Bowman Zhu-MSFT
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing