microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.46k stars 2.6k forks source link

Dynamic secure filename for InstallAppleProvisioningProfile based on variable value set on steps #16135

Closed superandrew closed 2 years ago

superandrew commented 2 years ago

Note

Issues in this repo are for tracking bugs, feature requests and questions for the tasks in this repo

For a list:
https://github.com/Microsoft/azure-pipelines-tasks/tree/master/Tasks

If you have an issue or request for the Azure Pipelines service, use developer community instead:

https://developercommunity.visualstudio.com/spaces/21/index.html )

Required Information

Entering this information will route you directly to the right team and expedite traction.

Question, Bug, or Feature?
Type: Question

Enter Task Name: InstallAppleProvisioningProfile

list here (V# not needed):
https://github.com/Microsoft/azure-pipelines-tasks/tree/master/Tasks

Environment

Azure Pipeline, on behalf of a customer

Issue Description

[Include task name(s), screenshots and any other relevant details] When we use InstallAppleProvisioningProfile the pipeline runs a pre-task. In this pretask it installs the provisionin profile before using it in the task. Since we have an environment variable which is set to the type of provisioning profile we want to install (e.g. dev, qa, prod) this determines the name of the file to be installed.

However we noticed that the variable, which is set dnamically based on the branch on the configuration task which run before the iOs task, that variable isn't set when the pre-task runs.


jobs:

  - job: configuration
    steps:
    - pwsh: |
        Write-Host "##vso[task.setvariable variable=country;]$(country)"
        Write-Host "##vso[task.setvariable variable=locale;]$(locale)"
        If ("$(Build.SourceBranchName)" -eq "master") {
          Write-Host "##vso[task.setvariable variable=bundleID;]$(prodBundleId)"
          Write-Host "##vso[task.setvariable variable=flavour;]prod"
        }
        If ("$(Build.SourceBranchName)" -eq "candidate") {
          Write-Host "##vso[task.setvariable variable=bundleID;]$(preprodBundleId)"
          Write-Host "##vso[task.setvariable variable=flavour;]preprod"
        }
        If ("$(Build.SourceBranchName)" -eq "develop") {
          Write-Host "##vso[task.setvariable variable=bundleID;]$(devBundleId)"
          Write-Host "##vso[task.setvariable variable=flavour;]dev"
        }

and this is how it should take it

- task: InstallAppleProvisioningProfile@1
      inputs:
        provisioningProfileLocation: 'secureFiles'
        provProfileSecureFile: 'DistProf_$(flavour).mobileprovision'

Any Idea on how this could be achieved?

Task logs

CleanShot 2022-04-12 at 10 21 24@2x

Troubleshooting

Checkout how to troubleshoot failures and collect debug logs: https://docs.microsoft.com/en-us/vsts/build-release/actions/troubleshooting

superandrew commented 2 years ago

in the end we managed with dynamic steps.

kkla320 commented 1 year ago

@superandrew I am running into the same problem. Can you provide the solution you came up with? It would really help me

SaltyTiefling commented 1 year ago

@superandrew yes please do tell cause I'm having the same problem and NEED help

superandrew commented 1 year ago

this is the code we used to discriminate between branches and certificates that we needed to use per branch:

- task: InstallAppleProvisioningProfile@1
        condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'develop'))
        inputs:
          provisioningProfileLocation: "secureFiles"
          provProfileSecureFile
Saccomani commented 6 months ago

any solution? In my case the profile name will be stored in a manifest.json, and I need pro sign in execution time...

h3dkandi commented 2 months ago

The solution I end up with for my case was to add a UI Variable to the pipeline lets call it "provisioningFile". We upload a dummy secure file to use as a value so that when saving the YAML file it doesn't complain but running the pipe with it would give warning because it is a dummy file. The UI variable has no problems in being used in "provProfileSecureFile". In order to use it dynamically you have to call the pipeline trough the Azure REST API:

https://dev.azure.com/censored/censored/_apis/pipelines/57/runs?api-version=7.1-preview.1

{
    "resources": {
        "repositories": {
            "self": {
                "refName": "refs/heads/main"
            }
        }
    },
    "variables": {
        "provisioningFile": {
            "isSecret": false,
            "value": "your_dynamic_name.mobileprovision>"
        }
    }

}

You could just end it here and call the api from you server or wherever.

I suppose you could also make a new pipeline that dynamically "calculates" the name for the provisioning profile file and uses it in lets say bash curl to make the call to the previous pipeline with the api call.

🤢