Automate Build from Visual Studio Online using MSBuild & Jenkins - jenkins

I want to build the code using MSbuild Script in Jenkins. My code repository is on Visual Studio Online. The below script does not copy anything in the output folder on my local machine. Whereas if I am using the same script on my local machine it works fine. Below is the script I am using for my build:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<BuildArtifactsDir Include="D:\Jenkins\jobs\Test\workspace\BuildArtifacts\"/>
<TeamFoundationServerUrl Include="https://XXX.visualstudio.com/DefaultCollection/XXX-XXX/"/>
<SolutionFile Include="$(TeamFoundationServerUrl)*.sln"/>
</ItemGroup>
<PropertyGroup>
<Configuration Condition="'$(Configuration)'=='' ">Release</Configuration>
<BuildPlatForm Condition="'$(BuildPlatForm)'=='' ">Any CPU</BuildPlatForm>
</PropertyGroup>
<Target Name="Compile" DependsOnTargets="Init">
<MSBuild Projects="#(SolutionFile)" Targets="Rebuild"
Properties="OutDir=%(BuildArtifactsDir.FullPath);Configuration=$(Configuration);Platform=$(BuildPlatform)"/>
</Target>
<Target Name="Init">
<MakeDir Directories="#(BuildArtifactsDir)"/>
</Target>
My Environment:
Jenkins: On my local host.
MSBuild Plugin in Jenkins.
Visual Studio Online for Code repository.

You cannot get the solution from VSO/TFS via msbuild directly.
To connect to VSO/TFS server from Jenkins, you can install TFS Plug-in in your Jenkins server via "Manage Jenkins -> Manage Plugins -> Available -> Team Foundation Server Plug-in". And then configure your project like following:
The plug-in will get the latest solution from your VSO/TFS server and copy it to your Jenkins server, you can then update your msbuild script accordingly.
Please note that you need to use "Alternate authentication credentials" to log in VSO/TFS server with this plug-in. To enable this feature, sign in your VSO/TFS account, enable it under "My Profile/Security/Alternate authentication credentials".

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).

Downloading nexus artifacts

I am using ANT to build artifacts(finally all artifacts will be zipped in one zip file) and jenkins plugin 'Nexus Artifact Uploader' to upload artifact to nexus repository.
I want to download the artifact(zip file) from nexus repository using ANT OR jenkins plugin only. I am not supposed to use maven for this task. Also, unix commands like 'wget' or 'curl' are not allowed in my deployment environment. It fails with permission denied error. So, I want solution using either ANT or jenkins plugin only.
Can anyone please help.
You can use below ant project snippet to download artifacts from nexus
<project name="testdown" default="dependencies" basedir=".">
<target name="dependencies">
<mkdir dir="libraries" />
<get src="http://10.135.155.72:8081/repository/maven-central/log4j/log4j/1.2.9/log4j-1.2.9.jar" dest="liblibraries/log4j-1.2.9.jar" usetimestamp="true" />
</target>
</project>

environment specific db automation with tfs ci cd

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.

Use MSBuild to define SSRS projects RDL Schema version

I am working on a Continuous Integration project that builds a Microsoft SSRS solution. However the RDL files produced are not always of the same schema version, some of them appear in 2008 format, and others in 2010 etc as per the following:
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
Others appear like
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
I have a Build.proj file that is responsible for performing an MSBuild on the .sln files, and looks like the following:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTarget="Compile" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Target Name="Compile">
<MSBuild
Projects="$(BuildDirectory)\ReportsPrimary.sln"
Properties="Configuration=$(Environment)"
/>
<MSBuild
Projects="$(BuildDirectory)\ReportsSecondary.sln"
Properties="Configuration=$(Environment)"
/>
<MSBuild
Projects="$(BuildDirectory)\ReportsSpecial.sln"
Properties="Configuration=$(Environment)"
/>
</Target>
</Project>
I need a means of enforcing that the RDL schema produced from the build is the 2008 version. Is it possible to perform some configuration inside my Build.proj file so that the RDL format will adhere to the 2008 schema version?
If not how else can I achieve the same functionality? Any recommendations? CI is relatively new to me
Thanks all!
MSBuild does not support reporting projects and will not transform the RDL files into the correct format.
You can use the Visual Studio mechanism to build a SSRS project.
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe"
"MyReportingProjPath\MyReportingProj.sln" /build release
Update your report with the creaded RDL files.
https://blogs.infosupport.com/managing-ssrs-reports-with-powershell/

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.

Resources