当前位置: 首页 > 知识库问答 >
问题:

如何使用Cake.NET和Gitlab CI?

饶德本
2023-03-14

我有一个ASP.NET MVC应用程序。我试图使用Gitlab和Cake.net实现CI和CD。

stages:
  - build
build:
 stage: build
 script:
  - build.ps1
 only:
   - develop
concurrent = 1
check_interval = 0

[[runners]]
  name = "Development runner"
  url = "https://gitlab.com/ci"
  token = "***"
  executor = "shell"
  shell = "powershell"

Build.Cake

#tool "nuget:?package=xunit.runner.console"

var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var version = Argument("releaseNumber", "");

var solution = "src/Pentrugatit.sln";
var binFolder = "src/Presentation/Nop.Web/bin/";
var pluginsFolder = "src/Presentation/Nop.Web/Plugins/";

Task("Clean")
  .Does(() => {
    CleanDirectories(binFolder);
    CleanDirectories(pluginsFolder);
  });

Task("NuGetRestore")
  .Does(() => NuGetRestore(solution));

Task("Build")
  .IsDependentOn("Clean")
  .IsDependentOn("NuGetRestore")
  .Does(() => MSBuild(solution, new MSBuildSettings { Configuration = configuration }));

Task("Default")
  .IsDependentOn("Build");

RunTarget(target);

build.ps1(类似.NET默认文件)

<#
.SYNOPSIS
This is a Powershell script to bootstrap a Cake build.
.DESCRIPTION
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
and execute your Cake build script with the parameters you provide.
.PARAMETER Target
The build script target to run.
.PARAMETER Configuration
The build configuration to use.
.PARAMETER Verbosity
Specifies the amount of information to be displayed.
.PARAMETER WhatIf
Performs a dry run of the build script.
No tasks will be executed.
.PARAMETER ScriptArgs
Remaining arguments are added here.
.LINK
http://cakebuild.net
#>

[CmdletBinding()]
Param(
    [string]$Target = "Default",
    [ValidateSet("Release", "Debug")]
    [string]$Configuration = "Release",
    [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
    [string]$Verbosity = "Verbose",
    [switch]$WhatIf,
    [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
    [string[]]$ScriptArgs
)

$CakeVersion = "0.17.0"
$DotNetChannel = "preview";
$DotNetVersion = "1.0.0-preview2-003121";
$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.ps1";
$NugetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"

# Make sure tools folder exists
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
$ToolPath = Join-Path $PSScriptRoot "tools"
if (!(Test-Path $ToolPath)) {
    Write-Verbose "Creating tools directory..."
    New-Item -Path $ToolPath -Type directory | out-null
}

###########################################################################
# INSTALL .NET CORE CLI
###########################################################################

Function Remove-PathVariable([string]$VariableToRemove)
{
    $path = [Environment]::GetEnvironmentVariable("PATH", "User")
    if ($path -ne $null)
    {
        $newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
        [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
    }

    $path = [Environment]::GetEnvironmentVariable("PATH", "Process")
    if ($path -ne $null)
    {
        $newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
        [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
    }
}

# Get .NET Core CLI path if installed.
$FoundDotNetCliVersion = $null;
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
    $FoundDotNetCliVersion = dotnet --version;
}

if($FoundDotNetCliVersion -ne $DotNetVersion) {
    $InstallPath = Join-Path $PSScriptRoot ".dotnet"
    if (!(Test-Path $InstallPath)) {
        mkdir -Force $InstallPath | Out-Null;
    }
    (New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1");
    & $InstallPath\dotnet-install.ps1 -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath;

    Remove-PathVariable "$InstallPath"
    $env:PATH = "$InstallPath;$env:PATH"
    $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
    $env:DOTNET_CLI_TELEMETRY_OPTOUT=1
}

###########################################################################
# INSTALL NUGET
###########################################################################

# Make sure nuget.exe exists.
$NugetPath = Join-Path $ToolPath "nuget.exe"
if (!(Test-Path $NugetPath)) {
    Write-Host "Downloading NuGet.exe..."
    (New-Object System.Net.WebClient).DownloadFile($NugetUrl, $NugetPath);
}

###########################################################################
# INSTALL CAKE
###########################################################################

# Make sure Cake has been installed.
$CakePath = Join-Path $ToolPath "Cake.$CakeVersion/Cake.exe"
if (!(Test-Path $CakePath)) {
    Write-Host "Installing Cake..."
    Invoke-Expression "&`"$NugetPath`" install Cake -Version $CakeVersion -OutputDirectory `"$ToolPath`"" | Out-Null;
    if ($LASTEXITCODE -ne 0) {
        Throw "An error occured while restoring Cake from NuGet."
    }
}

###########################################################################
# RUN BUILD SCRIPT
###########################################################################

# Build the argument list.
$Arguments = @{
    target=$Target;
    configuration=$Configuration;
    verbosity=$Verbosity;
    dryrun=$WhatIf;
}.GetEnumerator() | %{"--{0}=`"{1}`"" -f $_.key, $_.value };

# Start Cake
Write-Host "Running build script..."
Invoke-Expression "& `"$CakePath`" `"build.cake`" $Arguments $ScriptArgs"
exit $LASTEXITCODE

共有1个答案

洪雨石
2023-03-14

你可以试着改变

  - build.ps1

to ;

  - PowerShell .\build.ps1
 类似资料:
  • 似乎有支持类-在包中。然而,我一直无法找到文档、示例、测试用例,以便在一组图表中使用这种排列/布局。 指针赞赏。

  • 问题内容: 我正在使用,但它会返回如下所示的意外结果: 为什么我得到这些结果? 问题答案: 您是否要使用学位?请记住,并且期望弧度。

  • 问题内容: 大家好, 我想调用 一次而不创建一个反复调用的 循环 ,我应该为此使用递归方法还是应该使用 ? 还请告诉我使用?谢谢 :) 问题答案: 设置一个 定期 计时器。它返回一个句柄,您可以将其传递来阻止它触发: 在浏览器上,保证句柄是一个不等于; 的数字。因此,为“未设置计时器”设置一个方便的标志值。(其他平台可能返回其他值;例如,NodeJS的计时器函数返回一个对象。) 要将功能安排为 仅

  • 在成功运行JUnit4测试后,我试图将JUnit5与Gradle一起使用。 而我唯一的测试包含 我觉得这很奇怪! 我的生成文件是 我的文件夹结构是,使用包, 在我使用的IntelliJ2017.1.3中,模块结构如下所示 因为Gradle现在想要源代码和测试在他们自己的包中。 使用gradle在intellij中从JUnit4升级到JUnit5 链接回到上面的问题,并链接到这个Jetbrains博

  • 然后,为了在中调度作业,我使用了: 此外,为了实际执行,我让它像这样工作: 如上所述,所有这些过去在使用XML-配置时都能正常工作。 现在,使用java-config时,在失败 对于java-configuration,我设置,如下所示: 如何使用java-config在中插入对的引用?

  • 我在一个集群中使用Kerberos部署了NiFi,为了访问UI,我使用了HAProxy。我可以通过单独的节点URL访问NiFi UI,但它不能与loadbalncer URL一起工作,并得到以下错误 请求包含无效的主机标头 我认为可以通过nifi.web.proxy.host和nifi.web.proxy.context.path参数来修复。我尝试了这两个参数,但问题仍然存在。