Конвейер сборки компакт-диска Azure CI с gulp для sitecore в Private Agent - PullRequest
2 голосов
/ 16 мая 2019

у нас есть проект Sitecore с принципом спирали и, используя задачу gulp, мы можем без каких-либо проблем опубликовать приложение на локальном компьютере (dev-машине).

нам нужно реализовать CI / CD с конвейером Azure, добавив всю задачу для конвейера сборки Azure, такую ​​как решение для сборки, установка npm и задача gulp для публикации приложения,

Build taks

Задание глотка: «CI-And-Prepare-Files-CM-CD»

но мы столкнулись с проблемой при выполнении задачи gulp because it is being used by another process.

Сообщение об ошибке приведено ниже.

C: \ Program Files (x86) \ Microsoft Visual Studio \ 2017 \ Professional \ MSBuild \ Microsoft \ VisualStudio \ v15.0 \ Web \ Deploy \ Microsoft.Web.Publishing.Deploy.FileSystem.targets (96,5): ошибка: копирование файла obj \ Release \ Package \ PackageTmp \ bin \ DocumentFormat.OpenXml.dll для C: \ agent_work \ 2 \ s \ Deploy \ Сайт \ Bin \ DocumentFormat.OpenXml.dll не удалось. Процесс не может получить доступ к файлу 'C: \ agent_work \ 2 \ s \ Deploy \ Сайт \ Bin \ DocumentFormat.OpenXml.dll' потому что он используется другим процессом. [C: \ agent_work \ 2 \ s \ SRC \ Project \ MyProject \ код \ myproject.Site.csproj]

Ниже мои глоточные задания

var gulp = require("gulp");
var gutil = require("gulp-util");
var foreach = require("gulp-foreach");
var rimrafDir = require("rimraf");
var rimraf = require("gulp-rimraf");
var runSequence = require("run-sequence");
var fs = require("fs");
var path = require("path");
var xmlpoke = require("xmlpoke");
//var config = require("./gulpfile.js").config;
var gulpConfig = require("./gulp-config.js")();
var unicorn = require("./scripts/unicorn.js");
var webRootBackup = gulpConfig.webRoot;

var msbuild = require("gulp-msbuild");
var debug = require("gulp-debug");
var clean = require('gulp-clean');
var nugetRestore = require('gulp-nuget-restore');
module.exports.config = gulpConfig;

var webTransformationsToBuildFrom = path.resolve("./ConfigsToBuildFrom/Website");
var webCDTransformationsToBuildFrom = path.resolve("./ConfigsToBuildFrom/WebsiteCD");
var dataFolder = path.resolve("./Deploy/Website/Data/App_Data");
var tempWebsite = path.resolve("./Deploy/Website");
var tempWebsiteCD = path.resolve("./Deploy/WebsiteCD");
gulpConfig.webRoot = tempWebsite;


gulp.task("CI-And-Prepare-Files-CM-CD", function (callback) {
    runSequence(
        "CI-Clean",
        "CI-Copy-Configs-CM",
        "CI-Publish",
       // "CI-Copy-Website-CD",
       // "CI-Copy-Configs-CD",
        "CI-Prepare-Files-CM",
       // "CI-Prepare-Files-CD",
        //"CI-Apply-Xml-Transform-CM",
       // "CI-Apply-Xml-Transform-CD",
          "CI-Copy-Items-For-Unicorn",
          "CI-Clean",
        callback);
});

gulp.task("CI-Clean", function (callback) {
    rimrafDir.sync(path.resolve("./Deploy"));
    callback();

});

gulp.task("CI-Copy-Configs-CM", function () {
    return gulp.src(webTransformationsToBuildFrom + "/**")
        .pipe(gulp.dest(tempWebsite));
});

gulp.task("CI-Publish", function (callback) {
    //gulpConfig.webRoot = path.resolve("./");
    gulpConfig.buildConfiguration = "Release";
   // fs.mkdirSync(gulpConfig.webRoot);
    runSequence(
        "Build-Solution",
        "Publish-Foundation-Projects",
        "Publish-Feature-Projects",
        "Publish-Project-Projects",
        callback);
});

gulp.task("CI-Copy-Website-CD", function () {
    return gulp.src(tempWebsite + "/**")
        .pipe(gulp.dest(tempWebsiteCD));
});

gulp.task("CI-Prepare-Files-CM", function (callback) {
    var excludeList = [
        tempWebsite + "\\bin\\{Sitecore,Lucene,Newtonsoft,System,Microsoft,Web,Antlr3}*dll",
        tempWebsite + "\\bin\\*.pdb",
        tempWebsite + "\\compilerconfig.json.defaults",
        tempWebsite + "\\packages.config",
        tempWebsite + "\\App_Config\\Include\\{Feature,Foundation,Project}\\{z.*DevSettings.config,Website.config}",
        tempWebsite + "\\App_Data\\*",
        tempWebsite + "\\Unicorn\\*",
        "!" + tempWebsite + "\\bin\\Sitecore.Support*dll",    
        tempWebsite + "\\bin\\{Sitecore.Foundation.Installer}*",
        tempWebsite + "\\App_Config\\Include\\Foundation\\Foundation.Installer.config",
        tempWebsite + "\\README.md",
        tempWebsite + "\\Web*.config",
        tempWebsite + "\\bin\\{App_Config,roslyn,Scripts}",
        tempWebsite + "\\bin\\HtmlAgilityPack*dll",
        tempWebsite + "\\bin\\ICSharpCode.SharpZipLib*dll",
        tempWebsite + "\\bin\\Microsoft.Extensions.DependencyInjection*dll",
        tempWebsite + "\\bin\\MongoDB.Driver*dll",
        tempWebsite + "\\bin\\Microsoft.Web.XmlTransform*dll"
    ];
    console.log(excludeList);
    return gulp.src(excludeList, { read: false })
               .pipe(clean({ force: true }));
});

gulp.task("CI-Prepare-Files-CD", function (callback) {
    var excludeList = [
        tempWebsiteCD + "\\bin\\{Sitecore,Lucene,Newtonsoft,System,Microsoft.Web.Infrastructure}*dll",
        tempWebsiteCD + "\\bin\\*.pdb",
        tempWebsiteCD + "\\compilerconfig.json.defaults",
        tempWebsiteCD + "\\packages.config",
        tempWebsiteCD + "\\App_Config\\Include\\{Feature,Foundation,Project}\\z.*DevSettings.config",
        tempWebsiteCD + "\\App_Data\\*",
        "!" + tempWebsiteCD + "\\bin\\Sitecore.Support*dll",
        "!" + tempWebsiteCD + "\\bin\\Sitecore.{Feature,Foundation,Project}*dll",
        tempWebsiteCD + "\\bin\\{Sitecore.Foundation.Installer}*",
        tempWebsiteCD + "\\App_Config\\Include\\Rainbow",
        tempWebsiteCD + "\\App_Config\\Include\\Unicorn",
        tempWebsiteCD + "\\App_Config\\Include\\Rainbow*.config",
        tempWebsiteCD + "\\App_Config\\Include\\Unicorn*.config",
        tempWebsiteCD + "\\App_Config\\Include\\Foundation\\*.Serialization.config",
        tempWebsiteCD + "\\App_Config\\Include\\Feature\\*.Serialization.config",
        tempWebsiteCD + "\\App_Config\\Include\\Project\\*.Serialization.config",
        tempWebsiteCD + "\\App_Config\\Include\\DataFolderUnicornMaster.config",
        tempWebsiteCD + "\\App_Config\\Include\\Foundation\\Foundation.Installer.config",
        tempWebsiteCD + "\\README.md",
        tempWebsiteCD + "\\bin\\HtmlAgilityPack*dll",
        tempWebsiteCD + "\\bin\\ICSharpCode.SharpZipLib*dll",
        tempWebsiteCD + "\\bin\\Microsoft.Extensions.DependencyInjection*dll",
        tempWebsiteCD + "\\bin\\MongoDB.Driver*dll",
        tempWebsiteCD + "\\bin\\Microsoft.Web.XmlTransform*dll",
        tempWebsiteCD + "\\bin\\Rainbow*dll",
        tempWebsiteCD + "\\bin\\Unicorn*dll",
        tempWebsiteCD + "\\bin\\Kamsar.WebConsole*dll"
    ];
    console.log(excludeList);

    return gulp.src(excludeList, { read: false }).pipe(rimraf({ force: true }));
});

gulp.task("CI-Copy-Items-For-Unicorn", function () {

    return gulp.src("./Unicorn/**/*.yml")
               .pipe(gulp.dest(dataFolder + "/Unicorn/"));
});

gulp.task("CI-Sync-Unicorn-CM", function (callback) {
    var options = {};
    options.siteHostName = "http://qa.com/";//habitat.getStageUrl()"";
    options.authenticationConfigFile = tempWebsite + "/App_config/Include/Foundation/Unicorn/Unicorn.SharedSecret.config";

    unicorn(function () { return callback() }, options);
});

gulp.task("CI-Build", function (callback) {
    runSequence(
        "CI-Clean",
        "CI-Publish",
        "CI-Prepare-Package-Files",
        "CI-Copy-Items",
        callback);
});

gulp.task("Build-Solution", function () {
    var targets = ["Build"];

    return gulp.src("./" + gulpConfig.solutionName + ".sln")
        .pipe(debug({ title: "NuGet restore:" }))
        .pipe(nugetRestore())
        .pipe(debug({ title: "Building solution:" }))
        .pipe(msbuild({
            targets: targets,
            configuration: gulpConfig.buildConfiguration,
            logCommand: false,
            verbosity: "minimal",
            stdout: true,
            errorOnFail: true,
            maxcpucount: 0,
            toolsVersion: gulpConfig.MSBuildToolsVersion
        }));
});

gulp.task("CI-Copy-Items", function () {
    return gulp.src("./Unicorn/Configurations/**/*.yml")
        .pipe(gulp.dest('./Output/Data/Unicorn/'));
});

gulp.task("CI-Prepare-Package-Files", function (callback) {
    var excludeList = [
        gulpConfig.webRoot + "\\bin\\{Sitecore,Lucene,Newtonsoft,System,Microsoft.Web.Infrastructure}*dll",
        gulpConfig.webRoot + "\\compilerconfig.json.defaults",
        gulpConfig.webRoot + "\\packages.config",
        gulpConfig.webRoot + "\\App_Config\\Include\\{Feature,Foundation,Project}\\z.*DevSettings.config",
        "!" + gulpConfig.webRoot + "\\bin\\Sitecore.Support*dll",
        "!" + gulpConfig.webRoot + "\\bin\\Sitecore.{Feature,Foundation,Habitat,Demo,Common}*dll"
    ];
    console.log(excludeList);

    return gulp.src(excludeList, { read: false }).pipe(rimraf({ force: true }));
});

var cleanProjectFiles = function (layerName) {
    const filesToDelete = [
        '.\\src\\'+layerName+'\\Core\\code\\obj\\Dev\\Package\\PackageTmp\\bin\\Sitecore*',
        '.\\src\\'+layerName+'\\Core\\code\\obj\\Dev\\Package\\PackageTmp\\bin\\roslyn*'
    ];
    console.log("Removing " + layerName + " configs/binaries");
    return gulp.src(filesToDelete, { read: false })
        .pipe(debug({ title: "====================Cleaning Projects================" }))
        .pipe(clean({ force: true }));
};

var publishProjects = function (location, dest) {
    dest = dest || gulpConfig.webRoot;
    var targets = ["Clean","Build"];

    console.log("publish to " + dest + " folder");
    return gulp.src([location + "/**/code/*.csproj"])
        .pipe(foreach(function (stream) {
            return stream
                .pipe(debug({ title: "Building project:" + stream}))
                .pipe(msbuild({
                    targets: targets,
                    configuration: gulpConfig.buildConfiguration,
                    logCommand: false,
                    verbosity: "minimal",
                    stdout: true,
                    errorOnFail: true,
                    maxcpucount: 0,
                    toolsVersion: gulpConfig.MSBuildToolsVersion,
                    properties: {
                        Platform: "AnyCpu",
                        DeployOnBuild: "true",
                        DeployDefaultTarget: "WebPublish",
                        WebPublishMethod: "FileSystem",
                        BuildProjectReferences: "false",
                        DeleteExistingFiles: "false",
                        publishUrl: dest,
                    }
                }));
        }));
};

gulp.task("Publish-Foundation-Projects", function () {

        publishProjects("./src/Foundation"),
        cleanProjectFiles("Foundation");
});

gulp.task("Publish-Feature-Projects", function () {

        publishProjects("./src/Feature"),
         cleanProjectFiles("Feature");
});

gulp.task("Publish-Project-Projects", function () {

        publishProjects("./src/Project"),
         cleanProjectFiles("Project");
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...