Forum Discussion

444456464's avatar
444456464
Copper Contributor
Nov 26, 2024

Pipeline CI/CD Azure DevOps

Hello, I am trying to create a deployment pipeline with YAML on Azure DevOps. I would like to export my power apps solution from my development environment to my test environment.
But the problem is that the .zip file is not created and the artifact is empty! Can you help me please?

 

trigger:
- main

pool:
  vmImage: 'windows-latest'

variables:
  SolutionName: "SOL"
  DevEnvironmentUrl: "orgXXXXXXX.crmXX.dynamics.com"
  RecipeEnvironmentUrl: "org0000000.crmXX.dynamics.com"

steps:
# Étape 1 : Installer PAC
- script: |
    echo "Installation de PowerApps CLI (PAC)..."
    npm install -g pac-cli
  displayName: "Installer PAC"

# Étape 2 : Vérifier l'installation de PAC
- script: |
    pac version
  displayName: "Vérifier l'installation de PAC"

# Étape 3 : Vérifier que le dossier de sortie existe avant l'exportation
- script: |
    echo "Vérification du répertoire de sortie avant l'exportation :"
    if not exist "$(Build.ArtifactStagingDirectory)\Solution" (
        echo "Le répertoire n'existe pas. Création du répertoire."
        mkdir "$(Build.ArtifactStagingDirectory)\Solution"
    ) else (
        echo "Le répertoire existe déjà."
    )
  displayName: "Vérifier ou créer le répertoire de sortie"

# Étape 4 : Exporter la solution depuis l'environnement de développement
- script: |
    pac auth create --url $(DevEnvironmentUrl) --name DevEnvironment
    pac solution export --name $(SolutionName) --output-folder "$(Build.ArtifactStagingDirectory)/Solution" --managed
    if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL%
    echo "Export terminé. Vérifiez si le fichier .zip a été créé."
  displayName: "Exporter la solution depuis l'environnement de développement"

# **Nouvelle étape : Vérifier le contenu du répertoire après l'exportation**
- script: |
    echo "Contenu du répertoire après l'exportation :"
    dir "$(Build.ArtifactStagingDirectory)/Solution"
  displayName: "Vérifier les fichiers exportés après l'exportation"

# Étape 5 : Copier les fichiers exportés
- task: CopyFiles@2
  inputs:
    SourceFolder: '$(Build.ArtifactStagingDirectory)/Solution'
    Contents: '**'
    TargetFolder: '$(Build.ArtifactStagingDirectory)/Solution'
  displayName: "Copier les fichiers exportés"

# Étape 6 : Publier les artefacts
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)/Solution'
    ArtifactName: 'SolutionExported'
  displayName: "Publier les artefacts de la solution exportée"

# Étape 7 : Importer la solution dans l'environnement de recette
- script: |
    pac auth create --url $(RecipeEnvironmentUrl) --name RecipeEnvironment
    pac solution import --path "$(Build.ArtifactStagingDirectory)/Solution/$(SolutionName).zip"
  displayName: "Importer la solution dans l'environnement de recette"

 

  • How about this?

     

    trigger:
    - main
    
    pool:
      vmImage: 'windows-latest'
    
    variables:
      SolutionName: "SOL"
      DevEnvironmentUrl: "orgXXXXXXX.crmXX.dynamics.com"
      RecipeEnvironmentUrl: "org0000000.crmXX.dynamics.com"
    
    steps:
    # Step 1: Install PAC
    - script: |
        echo "Installing PowerApps CLI (PAC)..."
        npm install -g pac-cli
      displayName: "Install PAC"
    
    # Step 2: Verify PAC Installation
    - script: |
        pac version
      displayName: "Verify PAC Installation"
    
    # Step 3: Check Output Directory Before Export
    - script: |
        echo "Checking output directory before export:"
        if not exist "$(Build.ArtifactStagingDirectory)\Solution" (
            echo "Directory does not exist. Creating directory."
            mkdir "$(Build.ArtifactStagingDirectory)\Solution"
        ) else (
            echo "Directory already exists."
        )
      displayName: "Check or Create Output Directory"
    
    # Step 4: Export Solution from Development Environment
    - script: |
        pac auth create --url $(DevEnvironmentUrl) --name DevEnvironment
        pac solution export --name $(SolutionName) --output-folder "$(Build.ArtifactStagingDirectory)/Solution" --managed
        if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL%
        echo "Export completed. Check if the .zip file was created."
      displayName: "Export Solution from Development Environment"
    
    # Step 5: Check Exported Files
    - script: |
        echo "Contents of the output directory after export:"
        dir "$(Build.ArtifactStagingDirectory)/Solution"
      displayName: "Check Exported Files"
    
    # Step 6: Copy Exported Files
    - task: CopyFiles@2
      inputs:
        SourceFolder: '$(Build.ArtifactStagingDirectory)/Solution'
        Contents: '**'
        TargetFolder: '$(Build.ArtifactStagingDirectory)/Solution'
      displayName: "Copy Exported Files"
    
    # Step 7: Publish Solution Artifacts
    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)/Solution'
        ArtifactName: 'SolutionExported'
      displayName: "Publish Solution Artifacts"
    
    # Step 8: Import Solution to Test Environment
    - script: |
        pac auth create --url $(RecipeEnvironmentUrl) --name RecipeEnvironment
        pac solution import --path "$(Build.ArtifactStagingDirectory)/Solution/$(SolutionName).zip"
      displayName: "Import Solution to Test Environment"

     

  • 444456464 

    Please try the below mentioned steps

    1. Environment Authentication - Ensure that pac auth create is successfully authenticating with your development environment (DevEnvironmentUrl). Check for authentication-related errors.

    2. Solution Name Validation - Verify that the SolutionName (SOL) exists in your PowerApps development environment. An incorrect name will prevent the export.

    3. Output Path - Check that the output folder path ($(Build.ArtifactStagingDirectory)/Solution) is correctly resolved. Add a debug step to display the path.

    4. Error Handling in Export Command - Ensure the pac solution export command is not silently failing. Add detailed logging to confirm its execution.

    5. CLI Installation - Confirm that the pac-cli is correctly installed and functioning by manually running pac version in the pipeline.


    trigger:
    - main

    pool:
      vmImage: 'windows-latest'

    variables:
      SolutionName: "SOL"
      DevEnvironmentUrl: "https://orgXXXXXXX.crmXX.dynamics.com"
      RecipeEnvironmentUrl: "https://org0000000.crmXX.dynamics.com"

    steps:
    # Step 1: Install PAC
    - script: |
        echo "Installing PowerApps CLI (PAC)..."
        npm install -g pac-cli
      displayName: "Install PAC CLI"

    # Step 2: Verify PAC Installation
    - script: |
        echo "PAC Version:"
        pac version
      displayName: "Verify PAC Installation"

    # Step 3: Ensure Output Directory Exists
    - script: |
        echo "Ensuring output directory exists..."
        mkdir "$(Build.ArtifactStagingDirectory)\Solution"
      displayName: "Create Output Directory"

    # Step 4: Export Solution from Dev Environment
    - script: |
        pac auth create --url $(DevEnvironmentUrl) --name DevEnvironment
        echo "Authenticating to Dev Environment..."
        pac solution export --name $(SolutionName) --output-folder "$(Build.ArtifactStagingDirectory)/Solution" --managed
        if %ERRORLEVEL% neq 0 (
            echo "Solution export failed!"
            exit /b %ERRORLEVEL%
        )
        echo "Solution export completed."
      displayName: "Export Solution from Dev Environment"

    # Step 5: Debug Output Directory Content
    - script: |
        echo "Contents of output directory:"
        dir "$(Build.ArtifactStagingDirectory)\Solution"
      displayName: "Debug Output Directory"

    # Step 6: Copy Exported Files
    - task: CopyFiles@2
      inputs:
        SourceFolder: '$(Build.ArtifactStagingDirectory)/Solution'
        Contents: '**'
        TargetFolder: '$(Build.ArtifactStagingDirectory)/Solution'
      displayName: "Copy Exported Files"

    # Step 7: Publish Artifacts
    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)/Solution'
        ArtifactName: 'SolutionExported'
      displayName: "Publish Solution Artifacts"

    # Step 8: Import Solution to Test Environment
    - script: |
        pac auth create --url $(RecipeEnvironmentUrl) --name RecipeEnvironment
        echo "Authenticating to Test Environment..."
        pac solution import --path "$(Build.ArtifactStagingDirectory)/Solution/$(SolutionName).zip"
        if %ERRORLEVEL% neq 0 (
            echo "Solution import failed!"
            exit /b %ERRORLEVEL%
        )
        echo "Solution import completed."
      displayName: "Import Solution to Test Environment"

Resources