Download a secure file to repo code in Azure Devops Pipelines - flutter

I am creating a Pipeline to automatically build and release a flutter app. On my machine the flutter build appbundle --release works just fine and also signs the app correctly. I reference a key and a properties file, which I both don't want to upload into the repo, but instead use the Library > Secure Files.
How can I either download these files onto my Agent to a specific position, or use the downloaded file path in my build.gradle?

You can utilize "Download Secure File task" to download from the library on to your agent.
reference: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/download-secure-file?view=azure-devops
https://learn.microsoft.com/en-us/azure/devops/pipelines/library/secure-files?view=azure-devops
- task: DownloadSecureFile#1
inputs:
secureFile: 'secureFile'
- task: CopyFiles#2
inputs:
SourceFolder: '$(Agent.TempDirectory)'
Contents: secureFile
TargetFolder: '$(Build.ArtifactStagingDirectory)'

Related

Is it possible to download the secure file to local machine or view its content in Azure DevOps with build administrator privilege?

We have a few already running pipelines in Azure DevOps with dbt orchestration. The profiles.yml file required for the dbt tasks in the pipelines was uploaded to the secure file in DevOps a long time ago.
Now, we have built a new pipeline by orchestrating dbt. As we can't have two profiles.yml files, we are required to update the existing one in the secure file in DevOps.
Also, we have not seen the content of the existing secure file so we are afraid to make the decision to replace the existing file because it would impact the already running pipelines.
Could you please let me know whether we have any possible solution to download the secure file to our local machine or view its content in DevOps if we have the build administrator access?
Thanks.
I am afraid that you are not able to directly download the file to local machine.
I suggest that you can use the Download secure file task to download the secure file and then you can upload the secure file to Build artifacts.
Here is an example:
steps:
- task: DownloadSecureFile#1
displayName: 'Download secure file'
inputs:
secureFile: Certificates.p12
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(DOWNLOADSECUREFILE.SECUREFILEPATH)'
You can find the secure file in Build artifacts.

Unable to publish to File Share in Azure build pipeline

I am switching our pipelines from using on-prem build agent pool to a Hybrid Activation build agent (on-prem server with SSM Agent installed).
I am hitting a small issue when building our artefact. Our build pipeline does not seem to be able to publish the build artefact to the below File Share path on the new agent pool:
\\vwcnexstore08.comp.internal.corp\tfs_scm_drop\BuildDrops\$(System.TeamProject)\$(Build.DefinitionName)\$(Build.BuildNumber)
I am getting this error when I run the build:
Publishing build artifacts failed with an error: Unable to create directory '\\vwcnexstore08.comp.internal.corp\tfs_scm_drop\BuildDrops\CarEvaluator\CarEvaluator (dev branch)\CarEvaluator (dev
branch)_2.0.0293\drop'.
Unable to verify the directory exists: '\\vwcnexstore08.comp.internal.corp\tfs_scm_drop\BuildDrops\CarEvaluator\CarEvaluator (dev branch)\CarEvaluator (dev branch)_2.0.0293\drop'.
If directory is a file share, please verify the share name is correct, the share is online, and the current process has permission to access the share.
This is my PublishBuildArtifacts task
steps:
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: '$(Parameters.ArtifactName)'
publishLocation: FilePath
TargetPath: '\\vwcnexstore08.comp.internal.corp\tfs_scm_drop\BuildDrops\$(System.TeamProject)\$(Build.DefinitionName)\$(Build.BuildNumber)'
Note: The above used to work fine with the previous Agent pool
Could someone please share what I am doing wrong?
Unable to publish to File Share in Azure build pipeline
According to the document Publish Build Artifacts task:
The path must be a fully-qualified path or a valid path relative to the root directory of your repository.
So, you should make sure the TargetPath could be access on your on-prem server.
On the other hand, if the TargetPath is not share for everyone, the project build service account (“BuildService (orgname)”) is in the whitelist for access.

How to generate a build artifact in Azure Devops through Powershell

I would need to have a build definition totally included inside a powershell script.
I can install dotnet, restore packages, build everything, and now I need to create an artifact.
I cannot find a way to call in Powershell the equivalent of the task PublishBuildArtifacts#1, nothing comes up also googling everywhere. It shouldn't be difficult...
Thanks in advance.
Maybe I found it, finally: I will try it using this documentation:
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/artifacts/create?view=azure-devops-rest-4.1
'Publish build artifacts' should solve it.
I would also add a task to archive the files to be considered artifacts before the publish.
The build report now shows a link to download the files produced by the powershell script.
Summary:
Archive task to $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
Publish Build Artifacts task publishing $(Build.ArtifactStagingDirectory)
yaml for the archive:
- task: ArchiveFiles#2
displayName: 'Archive output'
inputs:
rootFolderOrFile: Deliver
yaml for the publish:
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'

How to find or add azure pipeline application published output folder for upload those files in to FTP

In the azure pipelines I'm trying to build a CI. I have added 'dotnet publish' in the agent job. But after publish, my application I have no idea where is those published files. There are no input field for enter output path.
I tried to use 'publishing artifacts' but it get wrong files
Here is my dotnet publish YAML
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: publish
workingDirectory: WebApplication1
How to find or add azure pipeline application published output folder for upload those files in to FTP
You can add the Arguments --output $(build.artifactstagingdirectory) in the Arguments option to specify the output path:
Then it will zip as one zip file(a.zip) in the $(build.artifactstagingdirectory) and you could use publishing build artifacts task to get it.
Hope this helps.

Azure DevOps release pipeline: Angular and .NET Core application

We're trying to release an Angular 7 / .NET Core application into Azure using the DevOps release pipelines. I have my build setup to create the .NET and Angular builds as separate artifacts which you can see in the screen shots below (under the Package or Folder box).
From what I've read it seems that you need to create two separate release tasks to deploy the builds to the web app. However the second build seems to be overriding the first which is causing the API not to start.
Does anyone know of a way to ensure the deployments in a given stage simply appends the changes rather than replacing them? Or is there something else I am missing here?
My recommendation would be to implement the following pattern for your pipeline:
'ng build --prod' the angular app in it's own job, and add the artifacts to your pipeline
'dotnet publish' the dotnet core api in it's own job, running in parallel with the angular job, and add the artifacts to your pipeline
Append the Angular and Dotnet Core artifacts together into a new artifact. This serves as your final package to deploy
Deploy the final package
You're missing step 3, so you'd want something like the following logic defined in YAML, where you create a new zip that represents your actual deployed bits in your pipeline. Then release that artifact, since it is the representation of what you have running on your instances.
- job: CreateReleaseArtifact
displayName: 'Package for shared-hosting of angular app and web api'
pool:
vmImage: windows-2019
dependsOn:
- BuildNetcore
- BuildAngularApp
condition: succeeded()
steps:
- checkout: none
- download: current
- task: CopyFiles#2
displayName: 'Copy WebApi Files'
inputs:
SourceFolder: $(Pipeline.Workspace)/api
Contents: '**/*'
TargetFolder: $(Pipeline.Workspace)/package
includeRootFolder: false
- task: CopyFiles#2
displayName: 'Copy Angular Files'
inputs:
SourceFolder: $(Pipeline.Workspace)/webapp
Contents: 'wwwroot/**'
TargetFolder: $(Pipeline.Workspace)/package
includeRootFolder: true
OverWrite: true
- publish: $(Pipeline.Workspace)/package
artifact: package
Does anyone know of a way to ensure the deployments in a given stage simply appends the changes rather than replacing them?
Based on my experience, in your case, after deploy the API or Angular 7, then I you could use the Kudu zip API to upload another one to the Azure WebApp.
You could use the Powershell task to do that. For more inforamtion about powershell demo code, you could refer to this link.
If creating another WebApp is acceptable, you could add a new WebApp and use the same service plan (no extral cost). Then you could deploy them separately.