Forum Discussion

safalkishore's avatar
safalkishore
Microsoft Employee
6 years ago
Solved

Automate PBIVIZ Cert Create and Install on Azure Devops CI/CD

In order to package a custom visual we need to run the below command :

 

pbiviz package

 

However a pre-requisite to this is the --create-cert and --install-cert steps.

 

Is it possible to automate the same on Azure Devops such that the CI can generate the required package. (*..pbiviz)

  • We were able to automate the same on Azure Devops using the usual NPM tasks. However the trick here was 'install the certificate' and using powershell 'to import this on the cert store' before packaging and generating the *.pbiviz file.

     

    Sample YAML file for reference - 

     

    pool:
    name: Azure Pipelines
    steps:
    - task: NodeTool@0
    displayName: 'Use Node 10.x'
    inputs:
    versionSpec: 10.x
    checkLatest: true

    - task: Npm@1
    displayName: 'npm install'
    inputs:
    workingDir: '$(System.DefaultWorkingDirectory)'
    verbose: false

    - task: Npm@1
    displayName: 'npm test'
    inputs:
    command: custom
    workingDir: '$(System.DefaultWorkingDirectory)'
    verbose: false
    customCommand: 'run test -- --reporter mocha-junit-reporter'
    enabled: false

    - task: Npm@1
    displayName: 'npm install pbiviz'
    inputs:
    command: custom
    workingDir: '$(System.DefaultWorkingDirectory)'
    verbose: false
    customCommand: 'install -g powerbi-visuals-tools'

    - task: Npm@1
    displayName: 'npm install cert'
    inputs:
    command: custom
    workingDir: '$(System.DefaultWorkingDirectory)'
    verbose: false
    customCommand: 'run cert'

    - powershell: |
    $ExtensionFile = "C:\npm\prefix\node_modules\powerbi-visuals-tools\config.json"

    $jsondata = Get-Content -Raw -Path $ExtensionFile | ConvertFrom-Json

    CERTUTIL -f -p $jsondata.server.passphrase -importpfx “C:\npm\prefix\node_modules\powerbi-visuals-tools\certs\PowerBICustomVisualTest_public.pfx”
    displayName: 'PowerShell Script - Import Pfx to Trusted Root '

    - task: Npm@1
    displayName: 'npm package'
    inputs:
    command: custom
    workingDir: '$(System.DefaultWorkingDirectory)'
    verbose: false
    customCommand: 'run package'

    - task: PublishBuildArtifacts@1
    displayName: 'Publish artifacts: drop'
    inputs:
    PathtoPublish: dist

    - task: PublishCodeCoverageResults@1
    displayName: 'Publish code coverage'
    inputs:
    codeCoverageTool: Cobertura
    summaryFileLocation: '$(Build.SourcesDirectory)/coverage/cobertura-coverage.xml'
    reportDirectory: '$(Build.SourcesDirectory)/coverage/'
    enabled: false

    - task: PublishTestResults@2
    displayName: 'Publish Test Results **/test-results.xml'
    inputs:
    testResultsFiles: '**/test-results.xml'
    enabled: false
    a

5 Replies

    • safalkishore's avatar
      safalkishore
      Microsoft Employee

      Thanks very much for this jppp ! Will also check this out and switch as its cleaner. However I recollect that when I simply ran the 'pbiviz package' cmd on the pipelines agent, it did throw back an error that the cmd is missing the cert installed.

  • safalkishore's avatar
    safalkishore
    Microsoft Employee

    We were able to automate the same on Azure Devops using the usual NPM tasks. However the trick here was 'install the certificate' and using powershell 'to import this on the cert store' before packaging and generating the *.pbiviz file.

     

    Sample YAML file for reference - 

     

    pool:
    name: Azure Pipelines
    steps:
    - task: NodeTool@0
    displayName: 'Use Node 10.x'
    inputs:
    versionSpec: 10.x
    checkLatest: true

    - task: Npm@1
    displayName: 'npm install'
    inputs:
    workingDir: '$(System.DefaultWorkingDirectory)'
    verbose: false

    - task: Npm@1
    displayName: 'npm test'
    inputs:
    command: custom
    workingDir: '$(System.DefaultWorkingDirectory)'
    verbose: false
    customCommand: 'run test -- --reporter mocha-junit-reporter'
    enabled: false

    - task: Npm@1
    displayName: 'npm install pbiviz'
    inputs:
    command: custom
    workingDir: '$(System.DefaultWorkingDirectory)'
    verbose: false
    customCommand: 'install -g powerbi-visuals-tools'

    - task: Npm@1
    displayName: 'npm install cert'
    inputs:
    command: custom
    workingDir: '$(System.DefaultWorkingDirectory)'
    verbose: false
    customCommand: 'run cert'

    - powershell: |
    $ExtensionFile = "C:\npm\prefix\node_modules\powerbi-visuals-tools\config.json"

    $jsondata = Get-Content -Raw -Path $ExtensionFile | ConvertFrom-Json

    CERTUTIL -f -p $jsondata.server.passphrase -importpfx “C:\npm\prefix\node_modules\powerbi-visuals-tools\certs\PowerBICustomVisualTest_public.pfx”
    displayName: 'PowerShell Script - Import Pfx to Trusted Root '

    - task: Npm@1
    displayName: 'npm package'
    inputs:
    command: custom
    workingDir: '$(System.DefaultWorkingDirectory)'
    verbose: false
    customCommand: 'run package'

    - task: PublishBuildArtifacts@1
    displayName: 'Publish artifacts: drop'
    inputs:
    PathtoPublish: dist

    - task: PublishCodeCoverageResults@1
    displayName: 'Publish code coverage'
    inputs:
    codeCoverageTool: Cobertura
    summaryFileLocation: '$(Build.SourcesDirectory)/coverage/cobertura-coverage.xml'
    reportDirectory: '$(Build.SourcesDirectory)/coverage/'
    enabled: false

    - task: PublishTestResults@2
    displayName: 'Publish Test Results **/test-results.xml'
    inputs:
    testResultsFiles: '**/test-results.xml'
    enabled: false
    a

    • shefalijha's avatar
      shefalijha
      Regular Visitor

      Hi All

      Thank you so much for the sample YAML. I tried the above option and tried to build my application.

      Getting error as below at the npn install cert step:

      npm ERR! missing script: cert
       
      npm ERR! A complete log of this run can be found in:
      npm ERR! /home/vsts/.npm/_logs/2021-10-30T07_46_06_594Z-debug.log
       
      Any leads would be of much help!
       
  • Hello,

     

    Applying npm command can build the visual. At my end, problem was ConsoleWriter javascript file was not found:

    C:\npm\prefix\node_modules\powerbi-visuals-tools\bin\pbiviz.js:30
    import ConsoleWriter from '../lib/ConsoleWriter.js';
    I had to copy folder ..\lib to  ..\AppData\Roaming\npm\node_modules\powerbi-visuals-tools\bin.
    Then build ran smootly.