我对Jenkins和管道不熟悉,我创建了Web API,并使用声明性管道在本地主机上构建和部署项目。 我在通过声明性管道执行Dotnet Run命令时遇到问题,它可以正常运行,但是无法完成该阶段(它会继续运行),因此我必须手动中止该阶段。 原因是因为dotnet run使用Kestrel Web服务器来运行.net核心应用。
下面是我的脚本:
def BatchFile = "C:\\WorkSpace\\Thoughts\\DotnetEXEC.bat"
pipeline{
agent any
environment {
dotnet ='C:\\Program Files (x86)\\dotnet\\'
sln = 'C:\\WorkSpace\\Thoughts\\Thoughts\\Thoughts.sln'
nugetexe = 'C:\\ProgramData\\chocolatey\\lib\\NuGet.CommandLine\\tools\\NuGet.exe'
packagedir='C:\\WorkSpace\\Thoughts\\packages'
trxFilePath= 'C:\\WorkSpace\\Thoughts\\Thoughts\\ThoughtsUnitTest\\TestResults'
mainDirectory='C:\\WorkSpace\\Thoughts'
testResultFileName='UnitTestRestult.trx'
publishDirectory='C:\\WorkSpace\\Thoughts\\Publish'
webAPIProjectFile='C:\\WorkSpace\\Thoughts\\Thoughts\\ThoughtsService\\ThoughtsService.csproj'
webAPIBuild='\\Thoughts\\Libraries\\ThoughtsService\\netcoreapp2.1'
}
triggers {
pollSCM 'H/15 * * * *'
}
stages {
stage('Checkout') {
steps {
git credentialsId: 'be9c1836-afb8-4e2a-9f8a-96888c92c77d', url: 'https://github.com/gargankurg/Thoughts', branch: 'develop'
}
}
stage('Restore packages'){
steps{
bat "%nugetexe% restore %sln%"
}
}
stage('Clean'){
steps{
bat "dotnet clean %sln%"
}
}
stage('Build'){
steps{
bat "dotnet build %sln% --configuration Release"
}
}
stage('Test: Unit Test'){
steps {
bat "dotnet test %sln% -l:trx;LogFileName=%testResultFileName%"
bat "copy %trxFilePath%\\%testResultFileName% %mainDirectory%"
}
}
stage('Publish'){
steps{
bat "dotnet publish %webAPIProjectFile% --framework netcoreapp2.1 --output %publishDirectory% --self-contained true --runtime osx.10.11-x64 "
}
}
stage('Run'){
steps{
bat "%mainDirectory%\\DotnetEXEC.bat"
}
}
}
}
cd C:\ WorkSpace \ Thoughts \ Thoughts \ ThoughtsService dotnet run --verbosity N