Cannot build angular project in Azure DevOps - azure

I have Angular project, that I want to build to Azure Web App
I created this yaml to build and deploy
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '18.x'
displayName: 'Install Node.js'
# - task: Npm#1
# inputs:
# command: 'install'
# workingDir: 'schooly-angular'
- script: npm install -g #angular/cli
displayName: 'npm install -g #angular/cli'
- script: yarn
displayName: 'yarn install'
- script: ng build --prod
displayName: 'ng build'
- task: PublishBuildArtifacts#1
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Azure subscription 1 (*********)'
appType: 'webAppLinux'
WebAppName: 'marifit-admin'
packageForLinux: 'dist/'
But I get this error when try to build
Clicking Authorize, doesn't helps
ow I can solve this?

It seems you do not have permission regard on the subscription Azure subscription 1 (*********) or this subscription does not exist. When edit YAML pipeline, click the Settings to show assistance >> choose your subscription >> click Authorize to create a service connection for this subscription.
If the authorization failed, means you do not have enough permission regard on that subscription. You need to get contributor or owner role regard on the subscription. To get related permission, you need get help from subscription owner. Here is Assign a user as an administrator of an Azure subscription for reference.

I have tried reproducing in my environment and got below results so sharing it here as further reference:
task: AzureRmWebAppDeployment#4
    inputs:
    ConnectionType: 'AzureRM'
    azureSubscription: 'Azure subscription 1 (*********)'
    appType: 'webAppLinux'
    WebAppName: 'marifit-admin'
    packageForLinux: 'dist/'
 The error seems the service connection used here was not existed. To create a proper service connection, follow the below steps. 
Step 1: Create a service principle for the subscription where the application resources are hosted using the below command in the cloud shell.    
$az ad sp create-for-rbac –name <service-principle-name> --scope /subscriptions/<subscription-id>
  
Make note of make note of password, appID and tenantID. 
Step 2: Create a service connection using the service principle just like mentioned in Step 1.
 Go to project settings > service connections > click on create new service connection.  
After filing all the details click on verify to confirm it is valid connection.
.
  
Make sure the azure subscription name above task match with the service connection name

Related

Create a pull request environment - Azure

I would want to create a pull request environment in Azure which gets deployed when a pull request is opened. Users can play around in that environment and find bugs. Once the bugs are fixed, and the PR is closed, I would want to delete that environment.
I am following through Sam Learns Azure and I was able to go through most steps, but its all .NET related.
Does anyone have an idea to do the same for a react-app?
I am also in favor of creating a new slot inside the app-service.
This is my modified code:
jobs:
- deployment: DeployWebServiceApp
displayName: "Deploy webservice app"
environment: ${{parameters.environment}}
pool:
vmImage: ubuntu-latest
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact#2
displayName: 'Download Pipeline Artifacts'
inputs:
artifactName: "$(Build.BuildId)"
buildType: 'current'
- task: AzureCLI#2
displayName: 'Deploy infrastructure with ARM templates'
inputs:
azureSubscription: "${{parameters.serviceConnection}}"
scriptType: bash
scriptLocation: inlineScript
inlineScript: az webapp deployment slot create --name ui-dev-$(prLC)
--resource-group rg-dev
--slot $(prLC)
--configuration-source app-dev
- task: AzureRmWebAppDeployment#3
displayName: 'Azure App Service Deploy: web service'
inputs:
azureSubscription: "${{parameters.serviceConnection}}"
appName: "${{parameters.appServiceName}}"
DeployToSlotFlag: true
ResourceGroupName: '${{parameters.resourceGroupName}}'
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
RemoveAdditionalFilesFlag: true
TakeAppOfflineFlag: true
RenameFilesFlag: true
Why Not. You can do that in below steps-
Create the Build Pipe which build your react app
In the build pipe set a VSTS var only when it is a PR. eg varPR = x
Create a Release pipe which deploys the app
Add one more task at the end of build pipe to call the release using webhook based on condition varPR = x.
Ref - Trigger azure pipeline via webhook?
The link you have shared is also cool that does the job same job in a single build pipe.

Deploy packages to multiple webapp service by azure pipeline single stage

I have more than 100 webapp service in azure. I want to deploy packages in 100 webapps by azure pipeline with one pipeline yml file. But I couldn't find any documentation like this. I got one microsoft documentation and they prefer to increase pipeline steps. If I have 100 webapps service, then have to add 100 steps for each deployment. This is not an efficient way and its time consuming. I want just like this step.
- task: AzureWebApp#1
displayName: 'Azure Web App Deploy'
inputs:
azureSubscription: '$(Parameters.connectedServiceName)'
appType: webApp
ResourceGroupName: $(group)
appName: 'JustGoTestAgain, justgotesttwo, webapp123, webapp555, webapp777 and so on ........'
package: '$(build.artifactstagingdirectory)/**/*.zip'
This yaml file is showing error. I couldn't find any essential extensions to fix it. I also couldn't find any azure powershell deployment command regarding to this issue. How can I get the solution?
You will not be able to do this like this. However you can use Azure Cli task:
- task: AzureCLI#2
displayName: Azure CLI
inputs:
azureSubscription: '$(Parameters.connectedServiceName)'
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
$apps= #('JustGoTestAgain, justgotesttwo, webapp123, webapp555, webapp777 and so on ........')
foreach ($app in $apps) {
az webapp deployment source config-zip -g $(group) -n $app --src '$(build.artifactstagingdirectory)/SOME_FOLDER/Artifact.zip'
}
And here you have more details about deployment itself
Annother approach with multiple task bu continuation if one fail is:
parameters:
- name: apps
type: object
default:
- JustGoTestAgain
- justgotesttwo
- and so on
steps:
- ${{ each app in parameters.apps}}:
- task: AzureWebApp#1
displayName: 'Azure Web App Deploy ${{ app }}'
continueOnError: true
inputs:
azureSubscription: '$(Parameters.connectedServiceName)'
appType: webApp
ResourceGroupName: $(group)
appName: ${{ app }}
package: '$(build.artifactstagingdirectory)/**/*.zip'
Thete was issue with space. Now is fine. Apart from that there is only one issue with connectedServiceName
Job Job: Step input azureSubscription references service connection $(Parameters.connectedServiceName) which could not be found. The service connection does not exist or has not been authorized for use. For authorization details, refer to https://aka.ms/yamlauthz. Job Job: Step input azureSubscription references service connection $(Parameters.connectedServiceName) which could not be found. The service connection does not exist or has not been authorized for use. For authorization details, refer to https://aka.ms/yamlauthz. Job Job: Step input azureSubscription references service connection $(Parameters.connectedServiceName) which could not be found. The service connection does not exist or has not been authorized for use. For authorization details, refer to https://aka.ms/yamlauthz.
Which I skipped here as you already have it on your solution.

Deploy terraform to azure through a pipeline in azure devops

I have deployed terraform to azure locally from the azure cli to success so I know the TF is working
I am now trying to build a pipeline to automate this process, however i get this error...
Error: Error building ARM Config: obtain subscription(xxxxxx) from Azure CLI: Error parsing json result from the Azure CLI: Error waiting for the Azure CLI: exit status 1
This error appears when the init is running in the pipeline.
This is what the pipeline looks like...
pool:
vmImage: ubuntu-latest
stages :
- stage: validate
jobs:
- job: validate
continueOnError: false
steps:
- task: ms-devlabs.custom-terraform-tasks.custom-terraform-installer-task.TerraformInstaller#0
displayName: 'install'
inputs:
terraformVersion: '0.14.10'
- bash: echo $(ls -latR)
- task: TerraformTaskV1#0
displayName: 'init'
inputs:
provider: 'azurerm'
command: 'init'
workingDirectory: "$(System.DefaultWorkingDirectory)"
backendServiceArm: 'Service-Fabric'
backendAzureRmResourceGroupName: 'fvs-uks-sf-rg-02'
backendAzureRmStorageAccountName: 'fvsukssfstorage'
backendAzureRmContainerName: 'fvs-uks-sf-backend01'
backendAzureRmKey: 'terraform.tfstate'
- task: TerraformTaskV1#0
displayName: 'validate'
inputs:
provider: 'azurerm'
command: 'validate'
- task: TerraformTaskV1#0
displayName: 'plan'
inputs:
provider: 'azurerm'
command: 'plan'
workingDirectory: "$(System.DefaultWorkingDirectory)"
environmentServiceNameAzureRM: 'test'
environmentServiceNameAWS: 'AWS-Azure-VPN'
This is what the backend.tf looks like...
provider "azurerm" {
alias = "hub"
subscription_id = "xxxxxxx"
features {}
}
provider "azurerm" {
features {}
}
terraform {
backend "azurerm" {
subscription_id = "xxxxxx"
resource_group_name = "xxxxxx"
storage_account_name = "xxxxxx"
container_name = "xxxxxx"
key = "terraform.tfstate"
}
}
I have also set up a service connection to azure via a service principal, that when authenticated connects successfully.
Any help is greatly appreciated
Deploy terraform to azure through a pipeline in azure devops
This issue should be related to the authorization.
When we use the service connection to authorization, it use the Service Principal instead of username/password to authenticate.
Then according to the terraform docs:
If you're authenticating using a Service Principal then it must have
permissions to both Read and write all applications and Sign in and
read user profile within the Windows Azure Active Directory API.
Please try to add a API permission for your principal, which you used to create the service connection:
Navigate to the Azure Active Directory overview within the Azure
Portal and select the App Registrations blade. Locate your registered
Application and click on its display name to manage it.
Go to the API Permissions blade for the Application and click the "Add
a permission" button. In the pane that opens, select "Azure Active
Directory Graph" (under the Supported Legacy APIs subheading). Do not
select "Microsoft Graph", as the provider does not currently make use
of this API.
Choose "Application Permissions" for the permission type, and check
the permissions you would like to assign. The permissions you need
will depend on which directory objects you are seeking to manage with
Terraform. We suggest the following permissions:
Application.ReadWrite.All
Directory.ReadWrite.All

How to deploy Strapi to Azure?

I installed Strapi with Mongodb locally.
I need to deploy it to Azure.
Strapi is commitet on Azure Git-repository.
I have created a App Service with Ubuntu on Azure.
How to deploy my Strapi to this?
Can I use pipeline?
I can't find any good documentaion/example how to do it. Help!
*************
UPDATE
*************
My results after trying the method described here:
https://github.com/youkou2/Strapi-On-Azure-WebApp
Build pipeline works without any error
Deploy pipeline works without any error
Deployed web site is empty.
I can describe what I have done, may be somebody can help me to find what I did wrong.
a) Build pipeline is
pool:
name: Azure Pipelines
steps:
- bash: |
yarn install
set NODE_ENV=PRODUCTION
yarn build
rm -rf .cache
rm -rf .git
displayName: Build
- task: ArchiveFiles#2
displayName: 'Archive ./'
inputs:
rootFolderOrFile: ./
includeRootFolder: false
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
*** It works ok, no errors ***
b) Deploy pipeline
steps:
- task: AzureRmWebAppDeployment#4
displayName: 'Deploy Azure App Service'
inputs:
azureSubscription: '$(Parameters.ConnectedServiceName)'
appType: '$(Parameters.WebAppKind)'
WebAppName: '$(Parameters.WebAppName)'
*** It works ok, no errors ***
c) Project is deployed to https://oskogencms.azurewebsites.net/
*** It is empty, why? ***
enter code here
Here is additional info around the deployment:
You can try to use zip deploy, The steps is npm install, create zip package, publish zip package, release zip package. For more information please have a look of this the offcial doc:
https://learn.microsoft.com/en-us/azure/app-service/deploy-zip
By the way, it seems deploy strapi to azure web app is not the recommended method.
https://strapi.io/documentation/3.0.0-beta.x/deployment/azure.html#azure
This is an article on deploying strapi to azure web app, the introduction is more detailed, also using zip deployment:(The only different between you is it is deployed to windows os. If you can use ftp, ftp deploy is also a choice.)
https://github.com/youkou2/Strapi-On-Azure-WebApp
Please check #ZiedBeta's sample in the following link:
https://github.com/strapi/strapi/issues/3580
Build pipeline:
pool:
name: Azure Pipelines
steps:
- bash: |
yarn install
yarn build
rm -rf .cache
rm -rf .git
displayName: build
- task: ArchiveFiles#2
displayName: 'Archive Strapi'
inputs:
rootFolderOrFile: ./
includeRootFolder: false
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
Development pipeline:
steps:
- task: AzureRmWebAppDeployment#4
displayName: 'Deploy Azure App Service'
inputs:
azureSubscription: '$(Parameters.ConnectedServiceName)'
appType: '$(Parameters.WebAppKind)'
WebAppName: '$(Parameters.WebAppName)'
enableCustomDeployment: true
DeploymentType: zipDeploy

Can't deploy MEAN stack app to Azure App Service via pipeline

I'm unable to deploy my app to azure app service. I've created a pipeline that fails at the azure app service deploy stage. I've been trying to get this working for a few days now. I've finally gotten it past the deploy app stage, but it just says Application Error when I click URL? and I configure it to point to the correct subscription. Web App for Linux, then chose the app-service call gc-dev, but I get errors still. I also get the same application error when trying to deploy app from vscode. It's possible both deployment types are dealing with exact same issue. IDK though.
I feel like it has something to do with the startup command since nothing is calling ng serve to launch angular code, but I'm not sure. Another thing that might be relevant to the issue is that all my angular services still have http://localhost:3000/api/ instead of some cloud url. Not sure if that's the issue with the inital page load though. I feel like it should still at least load the login screen. I appreciate any help!
Deploy Stage
The steps are as follows:
steps:
- task: Npm#1
displayName: 'install the #anguliar/cli'
inputs:
command: custom
workingDir: glass/
verbose: false
customCommand: 'install #angular/cli -g'
steps:
- task: Npm#1
displayName: 'install the project'
inputs:
workingDir: glass/
verbose: false
steps:
- task: Npm#1
displayName: 'build project'
inputs:
command: custom
workingDir: my-app/
verbose: false
customCommand: 'run build'
steps:
- task: Npm#1
displayName: 'npm install the dist/folder for express'
inputs:
workingDir: my-app/dist/
verbose: false
steps:
- task: Npm#1
displayName: 'Build the project'
inputs:
command: custom
workingDir: my-app
verbose: false
customCommand: 'run build'
steps:
- task: AzureRmWebAppDeployment#4
displayName: 'Azure App Service Deploy: my-app dev'
inputs:
azureSubscription: 'Azure subscription 1 (99c421dc-5cf5-444c-8df5-c71[![enter image description here][2]][2]02)'
appType: webAppLinux
WebAppName: 'gc-dev'
packageForLinux: my-app
WebConfigParameters: '-Handler iisnode -NodeStartFile index.js -appType node'
enableCustomDeployment: true
TakeAppOfflineFlag: false
Well, for one thing, this cannot be correct:
WebAppName: 'My-app - Dev'
You can't have spaces in App Service app names. It's part of the default URL.

Resources