Welcome to today’s post.
I will we discussing how to troubleshoot issues that occur when we configure and execute build, test and deployment pipelines (into an existing Azure app service) for .NET Core web applications within a TeamCity CI build configuration.
In one of my previous posts, I discussed how to configure a basic build configuration using TeamCity CI to check out the source from GitHub repository, then build and run a set of unit tests. In this post, I will be showing how to troubleshoot a unit test step during the build pipeline.
In this post I will discuss how to identify and resolve some common errors that will appear during a build, test, release pipeline within TeamCity.
Identifying Common Errors from the Build History
One of the most common errors we may experience is the one below from the build history:
It is clearly not helpful, so we inspect the build log to determine the cause:
[13:49:48][test] MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
The actual MSBuild error is shown below:
This error is most likely due to the working directory referenced in the build step referencing an source folder that does not have a project or solution file.
The working folder parameter is shown in the image below:
The common error is shown below:
On inspecting the build log we find more details:
[13:58:10][test] UnitTestMain.cs(4,7): error CS0246: The type or namespace name 'BookLoan' could not be found (are you missing a using directive or an assembly reference?)
The most likely cause for this error is due to one of the steps before the current build step returning an error. With missing namespace errors, it is possibly due to one of the following going into error:
- during a source checkout from the VCS
- building of the project source
- restoration of NuGet packages
To rectify this, check one of the following:
- network connectivity
- VCS credentials
- application compilation
- build steps are all enabled
In the next section, I will look at errors that are from deployment build tasks.
Errors Related to Deployment Build Tasks
The next type of error relates to deployment build tasks. User authentication or authorization error are quite common when fine tuning MSBuild deployment parameters. The error is show below in the build history:
The build log shows:
To determine root the cause we open the MSBuild deployment task and inspect the command line parameters.
Check the following:
- Build parameters for destination site credentials %deployusername% and %deploypwd%
- Check the destination (from the publish profile file) site is correct
- Check the application can deploy from the publish wizard without error
- Check the deployment credentials are correctly configured for the application within Azure App Services
- Incorrectly prefixing the user name with a “$” as it is in the publish profile. The parameter should not be prefixed with a $.
In the next section, I will cover errors that are caused by authorization when attempting to deploy to Azure App Services.
Errors Related to Authorization
The next type of error relates to authorization. The build history does not give much detail:
View the build log for further details:
Again, this has a similar remedy for the above authentication error: check the user deployment credentials in the build parameters match those in Azure app deployment center.
The next error is more cryptic to understand or troubleshoot. The error in the build history and detail shows:
Even though the publish task may work within Visual Studio, with MSBuild the target is treated like a new application!
Check the following:
- Site destination within the publisher profile.
- Deployment service URL is correct.
- Do not use MSBuild parameters that are already in the publish profile file.
Note: with the last point, any parameters that are duplicated in the MSBuild command outside of the /p:PublishProfile=… command will be regarded as replacing the corresponding setting in Azure, and deployments from MSDeploy only allow existing deployments without changing site settings.
For example, using the following build parameters in this way may lead to the above error:
/p:PublishProfile="Properties\PublishProfiles\BookLoanWebApp - Web Deploy.pubxml"
The following parameters below would cause the deployment to fail as the app name someapp and app path would be replacing the app and path that is existing in your Azure app service.
In this post, I have showed some common scenarios of issues that occur during the build and deployment steps of a continuous integration and deployment pipeline that result in a deployment of a web application to Azure App Services within Team City.
That’s all for today’s post!
I hope this post is useful and informative.
Andrew Halil is a blogger, author and software developer with expertise of many areas in the information technology industry including full-stack web and native cloud based development, test driven development and Devops.