environment specific db automation with tfs ci cd - tfs

I am trying automate db deployment using TFS CI/CD.
MSBuild for building the db which in turn creates dacpac
Winrm for db deployment to an on premise sql server
During build I am passing
MSBuild Arguments: /t:build /t:publish /p:SqlPublishProfilePath=db.publish.xml
Contents of db.publish.xml file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseName>dev_DB</TargetDatabaseName>
<DeployScriptFileName>db.sql</DeployScriptFileName>
<TargetConnectionString>Data Source=xxxx;Persist Security Info=True;User ID=sa;password=xxx;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True</TargetConnectionString>
<ProfileVersionNumber>1</ProfileVersionNumber>
</PropertyGroup>
</Project>
My release is currently configured to dev. And QA.. the release is working fine for dev. And it is not working for QA.
One observation is: the SqlPublishProfilePath in build is referring to publish file which is referring to Dev.
I would like to use same dacpack file for dev. And QA. As I have mentioned specific publish file in the release task.
release configuration

In Publish Profile argument, usually specify the path to the Publish profile XML file on the target machine or on a UNC share that is accessible by the machine administrator's credentials.
It seems variable $(devpublishprofile) point to a path on your dev machine. You have two option to fix your issue:
Put the Publish profile in a UNC share, and specify variable $(devpublishprofile) to the UNC share where both Dev and QA can access.
Copy the Publish profile from Dev to QA, and locate it in the same path as variable $(devpublishprofile) points to.

Related

Sonarqube ANT build azure devops for SAP Hybris

I am trying do sonarqube setup for SAP hybris, we use azure devops for Build and uses ant build to SAP hybris.
sonarqube is located in a seperate server backed by SQL DB and i confirmed it's working.
I want the ant build to communicate to sonarqube server.
In config--> local.properties i added the following sonarqube properties
sonar.projectName=xxx_xxxxxx_xx
sonar.jdbc.url=jdbc:sqlserver://Rxxxxxxxx02:1433;databaseName=soxxrxxxx;integratedSecurity=true
sonar.projectKey=xxx_xxxxxx_xxKey
sonar.projectVersion=1.0
sonar.excludedExtensions=acceleratorcms,acceleratorfacades,acceleratorservices,acceleratorstorefrontcommons,addonsupport,captchaaddon,commercefacades,platformservices
for SonarQube > 6.4
sonar.host.url=http://xxxxxxbldxx:9000
sonar.login=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
can anyone help me on how set this up??
Have you tried Measuring Code Quality with Sonar to configure SAP Commerce Cloud with SonarQube?
Also, when you use sonar.host.url, you don't need sonar.jdbc.url anymore.
the reason is that the ANT task shipped with the Hybris distribution is not compatible with Sonar version 8. In order to solve your problem there are two options:
a) Local workaround
Delete the JAR sonarqube-ant-task-XXX.jar in your platform folder ./platform/resources/ant/sonar/lib. Download a newer version (e.g. sonarqube-ant-task-2.7.0.1612.jar) and place it in the folder ./platform/resources/ant/sonar/lib.
Edit the file ./platform/resources/ant/sonar/sonar.xml and change the element for defining the sonar task. You have to include the new jar file:
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath>
<path path="${platformhome}/resources/ant/sonar/lib/sonarqube-ant-task-2.7.0.1612.jar" />
</classpath>
</taskdef>
After applying this change, you should be able to run ant sonarcheck without the mentioned error.
b) CI-supported solution
If you want to automate your sonar check on a CI server (e.g. Jenkins), you have to override the sonar resources provided by the SAP platform distribution. A common way to do this is to use the customize approach:
create a customize folder in your config folder, e.g. ./hybris/config/customize
add the new jar and modified sonar.xml to this customize directory. So the structure will be:
./hybris/config/customize/platform/resources/ant/sonar/lib/sonarqube-ant-task-2.7.0.1612.jar
./hybris/config/customize/platform/resources/ant/sonar/sonar.xml
In your build job you have to ensure that you invoke this step:
ant customize
This target will override the resources in the platform distribution. It is the offial way stated by SAP to handle such customizations.
After you invoked the ant customize target on your build server, you can build the platform (ant clean all) and invoke the sonar check (ant sonarcheck).

How to get TFS2015 Build (Build.vnext) and NuGet package restore to use custom package sources

I'm trying to get our TFS2015 Build (TFSBuild vnext) going along with VS Team Services.
Thus far most blogs and documentation has been helpful, except for when trying to build a project that uses custom package sources for NuGet automatic package restore.
I've successfully deployed an a Team Services Build Agent (the new mechanism for builds) and all seemed to go well until the build task to Restore NuGet packages failed.
The failure was due to custom/private package source not being picked up from the installed VS configuration, so those packages could not be found. The traditional packages from the default NuGet package feed did restore without issue.
How do I specify the additional package sources for NuGet to use when using an agent?
EDIT: vcastro asked about the NuGet Installer build step and defining paths in the configuration of that build step. The above is using the Visual Studio Build step and the integrated option to have NuGet restore packages. Refer this image for reference:
Alternatively you could also add a NuGet Installer build step before the Visual Studio Build step in your build configuration to restore all NuGet packages.
There you can pass the location of your private repo as argument to nuget.exe:
-source "https://www.nuget.org/api/v2/;http://mynugetserver"
I've scrounged the web with little success, but after fiddling the following will help:
OK It seems that the package sources configured for NuGet.config is stored per user account, e.g.
c:\Users\<<username>>\AppData\Roaming\NuGet\NuGet.config
My issue was harder to resolve, because the build agent was running as a Windows Service under the Local System account. So to get NuGet configuration to for the build, I had to use the following path instead:
64-bit Windows C:\Windows\SysWOW64\config\systemprofile\AppData\Roaming\NuGet\NuGet.Config
32-bit Windows C:\Windows\System32\config\systemprofile\AppData\Roaming\NuGet\NuGet.Config
You may need to have elevated permissions in order to create the NuGet subfolder and NuGet.Config file.
Note: I have no solution for using the Local Service account. The above only works for the Local System (or an actual user) account.
Add a NuGet.config to your project that specifies an alternate package location. The rules for resolution are well-defined and explained in the official documentation.
There is a new VSTS Task called "NuGet Installer" this allows you to check in your NuGet.config file and specify the different package sources. Run this task before you run MSBuild.
If you are using the VSTS NuGet Feed you will need to add the build service account to the feed to enable downloading of packages https://www.visualstudio.com/get-started/package/use/common-identities
One solution (works for me) is change account for tfs 2015 build agent service (on my build machine VSO Agent tsf.Agent-PC) to tfsagent, for example, and add Nuget.config to the C:\Users\tfsagent\AppData\Roaming\Nuget. That's all!
Specify your custom NuGet feed URL’s in the solution’s nuget.config file. Do not store any usernames & passwords in this file.
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="MyCompany" value="https://nuget.mycompany.com:443/nuget" />
Create username & password variables in your build definition in VSTS. Variables can be encrypted and will not be displayed in any of the build log outputs. Here I'll create MyCompanyNugetUser and MyCompanyNugetPwd variables.
In our build steps, we add a Powershell script as the first action, this will read the username & password variables and update the user level nuget.config file on the build machine. Below is the code snippet from my inline Powershell script:
Arguments:
$(MyCompanyNugetUser) $(MyCompanyNugetPwd)
Script:
param($user, $pwd)
$nugetFile = "$ENV:AGENT_HOMEDIRECTORY\agent\worker\tools\nuget.exe"
Write-Output "Looking for nuget.exe in $nugetFile"
if (-not (Test-Path $nugetFile))
{
Write-Error "nuget.exe could not be located."
return
}
Write-Output "nuget.exe located"
$cmd = "$nugetFile sources add -name MyCompany -source https://nuget.mycompany.com:443/nuget -username $user -password $pwd -StorePasswordInClearText"
Write-Output $cmd
iex $cmd
Next, we just continue to execute the default NuGet Restore step from Microsoft’s templates
More here: https://codingcase.com/2016/07/27/vsts-build-setup-custom-nuget-feeds-with-authentication/
HTH
In the RTM of Team Foundation Server 2015 you have to add a build step of the type "NuGet Installer", and restore the packages of the Solution file before you run the actual build process. In this task you can pass the argument -ConfigFile path/to/nuget.config which contains your repository path.
For Example:
<configuration>
<packageSources>
<add key="Internal Nuget" value="\\srv-nuget\Repo" />
</packageSources>
</configuration>
If you are having trouble getting this to work on UWP ONLY, then ensure that you have the CASE of the package name spelt correctly. If the case is wrong, then (for UWP only) our build server fails the build.
for instance, if you have a package called Com.Company.Components and update the package using "install-package com.company.components" (note the case of the initial letter) then the UWP build on the build server may fail to find the package in your local store.

MSBuild not copying files with PublishProfile

I have a Visual Studio 2013 solution with the full Orchard source code. When I use "Publish..." on the "Orchard.Web" project in Visual Studio, it correctly publishes the site to the File System destination I've configured into the .PubXml file that I used.
However, if I build this site using Jenkins, the files do not get copied to the destination. I've created a separate PubXml file that is used by Jenkins.
In my Jenkins job, I have two Build steps of interest. The first uses the src\Orchard.sln file with a command line argument of /p:Configuration=Release. This runs correctly, and builds the entire solution.
The second Build step, immediately after, uses the Build File of src\Orchard.Web\Orchard.Web.csproj and these command line arguments:
/p:DeployOnBuild=true
/p:PublishProfile="D:\workspace\Site\trunk\src\Orchard.Web\Properties\PublishProfiles\Jenkins.pubxml"
/p:VisualStudioVersion=12.0
/p:Configuration=Release
/p:Platform=AnyCPU
/v:minimal
/nologo
/p:WarningLevel=1
With this, the build and deploy seems to work - but doesn't. Here are some lines from the build output:
Copying all files to temporary location below for package/publish:
obj\Release\Package\PackageTmp.
Auto ConnectionString Transformed obj\Release\Package\PackageTmp\Shapes\Scripts\Web.config into obj\Release\CSAutoParameterize\transformed\Shapes\Scripts\Web.config.
(... about 200 more "Auto ConnectionString..." lines...)
Finished: SUCCESS
No where does it actually copy the files to the destination defined in the PUBXML file.
In contrast, in Visual Studio, the output looks similar, but transforms only 4 config files and includes lots of "Publishing folder x" lines:
(...)
Transformed Modules\SH.GoogleAnalytics\web.config using ....
Copying all files to temporary location below for package/publish:
obj\Release\Package\PackageTmp.
Publishing folder /...
Publishing folder bin...
(etc.)
(I have installed the latest Windows Azure SDK for .NET on the Jenkins server.)
I have the same trouble,that work for me:
/t:Rebuild
/p:DeployOnBuild=true
/p:PublishProfile=Jenkins_Publish
/p:Configuration=Release
do not use /p:VisualStudioVersion=xxx
This is kind of old, but I actually just set up Orchard to be able to get built via command line and MSBuild. Here is what I did:
/p:VisualStudioVersion=12.0;PublishProfile="example-profile";DeployProjA=true;FrameworkPathOverride="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v4.5";Configuration=Release;PublishProfileRootFolder=c:\Workspace\src\Orchard.Web\Properties\PublishProfiles;Password=ExamplePass
Since you are using Orchard you want to make sure that only the Orchard.Web project gets published so do not use DeployOnBuild=true. This will attempt to deploy every web project in the solution, which is a lot for Orchard. Instead follow the guidelines here to see how to deploy only the web project: http://sedodream.com/2013/03/06/HowToPublishOneWebProjectFromASolution.aspx

How to use MSBuild with TFS and SSIS

I'm a complete novice in using TFS Build definition and MSBuild scripts.
I want to automate my SSIS build and deployments and create a build definition which will build and deploy my SSIS project whenever I queue it up.
I found this project: http://sqlsrvintegrationsrv.codeplex.com/releases/view/82369
which allows you to create a DLL which you can place in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies
Then you can call the SSIS.MSBuild.proj (See end for this) with certain parameters like this in a visual studio command line:
MSBuild SSIS.MSBuild.proj /t:SSISBuild,SSISDeploy /p:SSISProj="MySSISProject",Configuration="DEV",,SSISServer="AB-CDE-FGH-I1\DEV",ProjectName="MySSISProject"
or I can put it in a BAT file like this:
%systemroot%\Microsoft.Net\Framework\v4.0.30319\MSBuild.exe SSIS.MSBuild.proj /t:SSISBuild,SSISDeploy /p:SSISProj="MySSISProject",Configuration="DEV",,SSISServer="AB-CDE-FGH-I1\DEV",ProjectName="MySSISProject"
It works fine when you run the BAT file, it builds and deploys the SSIS project.
Questions:
How can I use this so it is automated, so I can manually kick off a build and deployment from within VS/TFS? Using a build definition.
How can I ensure the correct configurations are selected, and the correct destination server? For example we have SSIS configurations for DEV, SIT, SYS, UAT, PRD. Each with its own server name. Do I need a separate build definition for each environment or is there a way to use one build definition?
Anything useful in using powershell somehow?
Here is SSIS.MSBuild.proj:
<?xml version="1.0" encoding="Windows-1252"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
DefaultTargets="SSISBuild;SSISDeploy">
<!--Requires a property called $(SSISProj) to be defined when this script is called-->
<UsingTask TaskName="DeploymentFileCompilerTask" AssemblyFile="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\Microsoft.SqlServer.IntegrationServices.Build.dll" />
<Target Name="SSISBuild" Condition="'$(SSISProj)' != ''">
<PropertyGroup>
<SSISProjPath>$(SSISProj)\$(SSISProj).dtproj</SSISProjPath>
</PropertyGroup>
<Message Text="**************Building SSIS project: $(SSISProjPath) for configuration: $(CONFIGURATION)**************" />
<DeploymentFileCompilerTask
InputProject="$(SSISProjPath)"
Configuration="$(CONFIGURATION)"
ProtectionLevel="DontSaveSensitive">
</DeploymentFileCompilerTask>
</Target>
<UsingTask TaskName="DeployProjectToCatalogTask" AssemblyFile="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\Microsoft.SqlServer.IntegrationServices.Build.dll" />
<Target Name="SSISDeploy" Condition="'$(SSISProj)' != ''">
<Message Text="**************Publishing SSIS project: $(SSISProj) to: $(SSISServer) to folder: $(PROJECTNAME)**************" />
<PropertyGroup>
<ISPac>$(SSISProj)\bin\$(CONFIGURATION)\$(SSISProj).ispac</ISPac>
</PropertyGroup>
<DeployProjectToCatalogTask
DeploymentFile="$(ISPac)"
Instance="$(SSISServer)"
Folder="$(PROJECTNAME)"
CreateFolder="true"/>
</Target>
</Project>
EDIT I tried adding some MSBuild Arguments to the TFS Build Definition. I tried various combinations of arguments, some with quotes, some without. I couldn't get it to work.
"C:\Users\me\Desktop\Buildssis\SSIS.MSBuild.proj" /t:SSISBuild,SSISDeploy /p:SSISProj="MySSISProject",Configuration="SIT",SSISServer="AB-CDE-FGH-I1\DEV",ProjectName="MySSISProject"
But I always get this error:
MSBUILD : error MSB1008: Only one project can be specified.
Switch: C:\Users\me\Desktop\Buildssis\SSIS.MSBuild.proj
For switch syntax, type "MSBuild /help"
I think you are prety close about the solution. you can call your package in console application and set the variables there. And for different DEV, SIT, SYS, UAT, PRD. you can have configuration file for the the console application. and then you can set the package variables in the console app. I hope it solve the preoblem. As much i could understand.
Please let me know if this is not related to your problem then explain your question a bit more.
To answer your question, the best way would be to use an UpgradeBuildTemplate for your team build.
Modify the build script to calls the tasks that you have created in the "AfterCompile" target of the build. See below
http://msdn.microsoft.com/en-us/library/aa337604(v=vs.100).aspx
You can pass build parameters in your team build definition. If you edit your build definition and edit Process, you will see option to pass MSBuild Arguments.

How to send build package back to teamcity as build artifact when building on agent/client side?

Our teamcity server uses Windows OS, so build process checkouts git source to agent Macs, and so build result package (*.ipa package) remains on agent. How to send this *.ipa build package to teamcity server, so it would appear as artifact?
At first, I have assumed teamcity should grab build result - ipa package by itself, so I'v added "OurProject/build/ipa/*.ipa" in "Artifact paths" settings in General settings of build configuration, but no artifacts appear under build result in teamcity website. Probably missing something obvious here :)
Artifact pattern like:
**/*.ipa
should publish all these files.
See also: http://confluence.jetbrains.com/display/TCD8/Configuring+General+Settings#ConfiguringGeneralSettings-artifactPaths
By default teamcity searches for artifacts inside workDir/yourCheckoutedSourceDir. My build dir is located at the root of teamcity folder on agent side and I'm using BUILD_DIR environment variable in custom scripts to set where build result should be saved. So and I'v used this environment variable in custom scripts using this format:
${BUILD_DIR}
My problem was teamcity does not recognize such format when using inside artifact paths field, so you need to use this format instead:
%env.BUILD_DIR%
If build dir is set to outside of checkout dir then the other solution would be to use relative paths like ../../Builds, but the first solution is more clearer in case the name of build dir would change.

Resources