admin管理员组

文章数量:1418112

Using Set-AdminPowerAppEnvironmentBackupRetentionPeriod is not working in my YAML-pipeline. I've tried the following steps below and it keeps on going untill it will be automatically cancel the job.

This is my pipeline and the set command that i'm using.

Pipeline with tasks

stages:
 stage: Power_Platform_Environment
 displayName: 'PS'
 jobs:
  - job: Create_Power_Platform_Environment
    displayName: 'PS'
    steps:
      - task: PowerPlatformToolInstaller@2
        displayName: "Power Platform Tool Installer"
        inputs:
          DefaultVersion: true
          AddToolsToPath: true

      - task: PowerPlatformCreateEnvironment@2
        displayName: 'Platform Create Environment'
        inputs:
          authenticationType: 'PowerPlatformSPN'
          PowerPlatformSPN: 'CZ-PowerPlatform-LowCode-PPAdmin'
          DisplayName: '$(EnvironmentName)'
          EnvironmentSku: 'Production'
          LocationName: 'europe'
          LanguageName: 'English'
          CurrencyName: 'EUR'
          DomainName: '$(DomainName)'
          SecurityGroupId: '$(SecurityGroupId)'
        name: sv1

      - task: PowerPlatformSetConnectionVariables@2
        displayName: 'Set Connection Variables'
        inputs:
          authenticationType: 'PowerPlatformSPN'
          PowerPlatformSPN: 'CZ-PowerPlatform-LowCode-PPAdmin'
        name: sv2

      - task: PowerShell@2
        displayName: Powershell Install-Update PowerApps Module
        inputs:
          targetType: "Inline"
          script: 
            Install-Module -Name Microsoft.PowerApps.Administration.PowerShell -Force -AllowClobber -Scope AllUsers

      - task: PowerShell@2
        displayName: Powershell Import PowerApps Module
        inputs:
          targetType: "Inline"
          script: 
            Import-Module -Name Microsoft.PowerApps.Administration.PowerShell -Verbose
            
      - task: PowerShell@2
        displayName: Connect-SPN 
        inputs:
          targetType: 'inline'
          script: |
            Write-Host "$(sv2.BuildTools.ApplicationId)"
            Write-Host "$(sv2.BuildTools.ClientSecret)"
            Write-Host "$(sv2.BuildTools.TenantId)"
            
            pac auth create --name SPN-PPAdmin --environment $(sv1.BuildTools.EnvironmentUrl) --applicationId $(sv2.BuildTools.ApplicationId) --clientSecret $(sv2.BuildTools.ClientSecret) --tenant $(sv2.BuildTools.TenantId)

      - task: PowerShell@2
        displayName: 'Set Retention period to 28 days'
        inputs:
          targetType: 'inline'
          script: |
            # Write your PowerShell commands here.
            Set-AdminPowerAppEnvironmentBackupRetentionPeriod -EnvironmentName $(sv1.BuildTools.EnvironmentUrl) -NewBackupRetentionPeriodInDays 28

Because using an azure agent, the powershell needs to have installed the module Microsoft.PowerApps.Administration.PowerShell. When importing this module with the -verbose parameter it shows me the right import, so succesful.

then I'm trying to get connected to my Service Principle, also succesfully.

Last step is setting the backup retention period to 28 days. This task will continue untill cancelled.

i've tried to change the period normally withing powershell, this works well.

Using Set-AdminPowerAppEnvironmentBackupRetentionPeriod is not working in my YAML-pipeline. I've tried the following steps below and it keeps on going untill it will be automatically cancel the job.

This is my pipeline and the set command that i'm using.

Pipeline with tasks

stages:
 stage: Power_Platform_Environment
 displayName: 'PS'
 jobs:
  - job: Create_Power_Platform_Environment
    displayName: 'PS'
    steps:
      - task: PowerPlatformToolInstaller@2
        displayName: "Power Platform Tool Installer"
        inputs:
          DefaultVersion: true
          AddToolsToPath: true

      - task: PowerPlatformCreateEnvironment@2
        displayName: 'Platform Create Environment'
        inputs:
          authenticationType: 'PowerPlatformSPN'
          PowerPlatformSPN: 'CZ-PowerPlatform-LowCode-PPAdmin'
          DisplayName: '$(EnvironmentName)'
          EnvironmentSku: 'Production'
          LocationName: 'europe'
          LanguageName: 'English'
          CurrencyName: 'EUR'
          DomainName: '$(DomainName)'
          SecurityGroupId: '$(SecurityGroupId)'
        name: sv1

      - task: PowerPlatformSetConnectionVariables@2
        displayName: 'Set Connection Variables'
        inputs:
          authenticationType: 'PowerPlatformSPN'
          PowerPlatformSPN: 'CZ-PowerPlatform-LowCode-PPAdmin'
        name: sv2

      - task: PowerShell@2
        displayName: Powershell Install-Update PowerApps Module
        inputs:
          targetType: "Inline"
          script: 
            Install-Module -Name Microsoft.PowerApps.Administration.PowerShell -Force -AllowClobber -Scope AllUsers

      - task: PowerShell@2
        displayName: Powershell Import PowerApps Module
        inputs:
          targetType: "Inline"
          script: 
            Import-Module -Name Microsoft.PowerApps.Administration.PowerShell -Verbose
            
      - task: PowerShell@2
        displayName: Connect-SPN 
        inputs:
          targetType: 'inline'
          script: |
            Write-Host "$(sv2.BuildTools.ApplicationId)"
            Write-Host "$(sv2.BuildTools.ClientSecret)"
            Write-Host "$(sv2.BuildTools.TenantId)"
            
            pac auth create --name SPN-PPAdmin --environment $(sv1.BuildTools.EnvironmentUrl) --applicationId $(sv2.BuildTools.ApplicationId) --clientSecret $(sv2.BuildTools.ClientSecret) --tenant $(sv2.BuildTools.TenantId)

      - task: PowerShell@2
        displayName: 'Set Retention period to 28 days'
        inputs:
          targetType: 'inline'
          script: |
            # Write your PowerShell commands here.
            Set-AdminPowerAppEnvironmentBackupRetentionPeriod -EnvironmentName $(sv1.BuildTools.EnvironmentUrl) -NewBackupRetentionPeriodInDays 28

Because using an azure agent, the powershell needs to have installed the module Microsoft.PowerApps.Administration.PowerShell. When importing this module with the -verbose parameter it shows me the right import, so succesful.

then I'm trying to get connected to my Service Principle, also succesfully.

Last step is setting the backup retention period to 28 days. This task will continue untill cancelled.

i've tried to change the period normally withing powershell, this works well.

Share Improve this question edited Feb 4 at 7:58 Steven D asked Jan 31 at 9:46 Steven DSteven D 113 bronze badges 6
  • If possible, please show more of the pipeline YAML, i.e. where you get the $(sv1.BuildTools.EnvironmentUrl) variable from. Also, is this being run from a MS-hosted or self-hosted agent? – GalnaGreta Commented Feb 1 at 9:08
  • When using the Set-AdminPowerAppEnvironmentBackupRetentionPeriod cmdlet in my test, an authentication prompt appears, requiring me to log in to my Azure account. This issue seems to be related to the authentication prompt that appears when running the cmdlet. The pipeline waits for the login until it is canceled. To avoid this issue, please ensure that your account is logged in before you run the command. – Miao Tian Commented Feb 3 at 6:24
  • @GalnaGreta, thanks for your reply. I've updated my yaml code. The create and set connection task come with output variables. in order to use these further down the pipeline, i'll have to set these sv1 and sv2. My pipeline is running on a MS-hosted agent. – Steven D Commented Feb 4 at 8:01
  • @MiaoTian-MSFT Thanks for your reply. First of all i've never seen a authentication prompt. I've tried to get the credentials from my Service Principle (see Powershell task: connect-SPN). this is working, and i'm connecting to the right SPN. I'm affraid that the set-command is not looking at my SPN. – Steven D Commented Feb 4 at 8:05
  • Hi @StevenD, thanks for your update. In a YAML pipeline, each task runs in its own PowerShell session. This means that the authentication context established in one task (like Connect-SPN) is not automatically carried over to subsequent tasks. To ensure that the Set-AdminPowerAppEnvironmentBackupRetentionPeriod command recognizes the SPN authentication, you can try to combine the Connect-SPN and Set commands in the same PowerShell task to ensure the authentication context is maintained. – Miao Tian Commented Feb 4 at 9:15
 |  Show 1 more comment

1 Answer 1

Reset to default 0

For now i've fixed the issue by using pac cli commands in my powershell task.

pac auth create 
pac auth update 
pac admin set-backup-retention-period

本文标签: