The library provides a set of pre-build [CAKE build] tasks. Those tasks could be used to simplify a configuration of CI/CD for Helix-based Sitecore projects.
Cake (C# Make) is a cross-platform build automation system with a C# DSL for tasks such as compiling code, copying files and folders, running unit tests, compressing files and building NuGet packages. It should be familiar for a Sitecore developers as script are written in C# and it is possible to use .NET dll and NuGet packages in them. The library also provides a set of ready tasks that could be configured with environment variables, arguments and inside script, which makes it highly suitable for DevOps. As those tasks are decoupled from your build server - it makes your process highly portable (TeamCity, Jenkins, VSTS or even local machine - doesn't really matter).
In order to use the library you need to follow the standard initial setup from CAKE. Once you have 3 required files build.ps1
, build.cake
and tools/packages.json
, open build.cake
and add following sections there:
// //////////////////////////////////////////////////
// Dependencies
// //////////////////////////////////////////////////
#tool nuget:?package=Cake.Sitecore&version=<current>
#load nuget:?package=Cake.Sitecore&version=<current>
// ... other includes
// //////////////////////////////////////////////////
// Arguments
// //////////////////////////////////////////////////
var Target = ArgumentOrEnvironmentVariable("target", "", "Default");
// //////////////////////////////////////////////////
// Prepare
// //////////////////////////////////////////////////
Sitecore.Constants.SetNames();
Sitecore.Parameters.InitParams(
context: Context, // Pass CAKE context to a library
msBuildToolVersion: MSBuildToolVersion.Default, // Select required version
solutionName: "Habitat", // Name of your solution
scSiteUrl: "https://sc9.local", // URL of a site
// ... other parameters
);
// //////////////////////////////////////////////////
// Tasks
// //////////////////////////////////////////////////
Task("Restore")
// predefined tasks could be used as a dependency for your build step
.IsDependentOn(Sitecore.Tasks.RestoreNuGetPackagesTask)
.IsDependentOn(Sitecore.Tasks.RestoreNpmPackagesTaskName)
;
// ... other tasks
// //////////////////////////////////////////////////
// Targets
// //////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Restore")
// ... other tasks
;
// //////////////////////////////////////////////////
// Execution
// //////////////////////////////////////////////////
RunTarget(Target);
Full version of this file can be found in samples
directory.
Executes basic configuration to optimize build performance (e.g. hide progress bars)
Removes items from project ./dist
and ./App_Data
directories in each project.
App_Data
contains unicorn serialization files that are copied from serialization folder before publish.
dist
holds client side artifacts, that are generated by webpack and also copied before publish.
Cleans artifacts (ARTIFACTS_DIR
) and output (OUTPUT_DIR
) directories
Restore NuGet packages for a solution
Restore Npm packages for a solution
Creates a file with detailed information about the build in publishing target directory (PUBLISHING_TARGET_DIR
). The file includes:
- current build version (
VERSION
) - branch name (
BRANCH_NAME
) that was used to generate it - commit SHA (
COMMIT
) - build number (
BUILD_NUMBER
)
and a time of its creation in UTC.
Updates version in packages.json
with current build version (VERSION
)
Updates Assembly.cs
version(ASSEMBLY_VERSION
)before the build in each project in source directory (SRC_DIR
).
Download license file from remote address (SC_LICENSE_URI
) to the (ROOT_DIR
).
Executes JS plugin to parse Unicorn files via npm run
and generate code. Script should be called sc:codegen
.
Executes front-end code build via calling npm run build:<your build configuration>
. Build configurations in taken from corresponding parameter (BUILD_CONFIGURATION
).
Runs MsBuild for a solution (SOLUTION_FILE_PATH
) with a specific build configuration (BUILD_CONFIGURATION
).
Executes all available tests for server-side code using xUnit. Result will be placed into (TESTS_OUTPUT_DIR
), also code coverage reports will be created in cobertura
format in (XUNIT_TESTS_COVERAGE_OUTPUT_DIR
) directory.
Executes all available tests for client-side code via npm run test-cover
. Result should be placed into (TESTS_OUTPUT_DIR
) including code coverage reports in cobertura
.
Merges available code coverage reports produces by previous steps. Generates an index
file in a coverage directory (TESTS_COVERAGE_OUTPUT_DIR
).
Copies Sitecore PowerShell Remoting (SPE) plugin assets from (LIBS_SPE_DIR
) to the publishing target directory (PUBLISHING_TARGET_DIR
).
Copies Sitecore Ship plugin assets from (LIBS_SHIP_DIR
) to the publishing target directory (PUBLISHING_TARGET_DIR
).
Transforms web.config
file located in config directory (SRC_CONFIGS_DIR
) and copy it the publishing target directory (PUBLISHING_TARGET_DIR
). This is required to make plugins work. (SC_NODE_ENV
) will define env:node
for Sitecore layers configurations.
Installs packages from a libs/packages
directory (LIBS_PACKAGES_DIR
) according to a node role (SC_NODE_ROLE
). packages will be delivered via Sitecore Ship (SC_SITE_URL
).
Publishes all Foundation-layer projects to the publishing target directory (PUBLISHING_TARGET_DIR
) using MsBuild.
Publishes all Feature-layer projects to the publishing target directory (PUBLISHING_TARGET_DIR
) using MsBuild.
Publishes all Project-layer projects to the publishing target directory (PUBLISHING_TARGET_DIR
) using MsBuild.
Exclude unnecessary files from target directory (ARTIFACTS_BUILD_DIR
).
Copy configuration files from source config directory (SRC_CONFIGS_DIR
) to artifact directory (ARTIFACTS_SRC_CONFIGS_DIR
).
Copy build scripts from source directory (SRC_SCRIPTS_DIR
) to artifact directory (ARTIFACTS_SRC_DIR
).
Copy Sitecore packages from source directory (LIBS_PACKAGES_DIR
) to artifact directory (ARTIFACTS_LIBS_PACKAGES_DIR
).
Executes Unicorn content synchronization using (SC_SITE_URL
). Secret required to authenticate services should be located in a config file (UNICORN_CONFIG_PATH
). List of configurations can be passed via parameter (UNICORN_CONFIGURATIONS
)
Any feedback, issues or pull requests pull requests are welcome and greatly appreciated.
Sample usage of a CAKE-build with Habitat could be found in here
Sitecore Powershell Extensions updated to version 5.0 "ScAdminUser" parameter default fixed - "admin" .nuspec version bumped
Fixed issue with wrong assembly version generation. Removed build number from assemsbly version and make it 0 by default. Otherwise it breaks reference for the nuget packages generated for the same {Major}.{Minor}.{Patch} version
Added new parameter Sitecore.Parameters.TestsFailImmediately with default boolean value = true. In case of failed unit tests parameter Sitecore.Parameters.TestsFailImmediately controls if tasks Sitecore.Tasks.RunServerUnitTestsTaskName and Sitecore.Tasks.RunClientUnitTestsTaskName should fail immediately or not. Otherwise if Sitecore.Parameters.TestsFailImmediately = false unit test execution will throw an exception in the task Sitecore.Tasks.MergeCoverageReportsTaskName. You can pass value to the parameter with argument: -TESTS_FAIL_IMMEDIATELY=false