首页 > 解决方案 > Jenkins Pipeline 失败但没有错误?

问题描述

我有以下管道脚本,它似乎在某些时候失败了。CredentialId 是正确的,github URL 是正确的,dotnet 的路径是正确的,而且我 99% 确定语法是正确的,因为输出(下面)正在正确读取我的脚本。所以,我只是想知道我是否做错了什么。

我以前从未使用过 Jenkins 或任何 CI/CD 工具,所以这对我来说是全新的。

我希望的目标是能够让Jenkins在每次与master合并时构建和运行一个.NET应用程序,但我只是想让它每小时成功构建,或者只是让它成功构建当我在 Jenkins 本身中单击立即构建时。

(另外,如果有一种简单的方法可以修改我的脚本以在每次主合并时运行,而不是每小时运行一次,那将非常有帮助!)

pipeline{
    agent any
    
    environment {
        dotnet ='C:\\Program Files (x86)\\dotnet\\'
        }
        
    triggers {
        pollSCM 'H * * * *'
    }
 
     stages{
         stage('Checkout') {
            steps {
                git credentialsId: '0b02e39b-17f0-4628-ba3d-24146ec7a469', url: 'https://github.com/bellingboe/OktaKenkinsCI.git', branch: 'master'
             }
          }
          
        stage('Restore packages'){
           steps{
              bat "dotnet restore C:\\Users\\Brenden\\Documents\\GitHub\\OktaKenkinsCI\\OktaKenkinsCI.csproj"
             }
          }
          
        stage('Clean'){
            steps{
                bat "dotnet clean C:\\Users\\Brenden\\Documents\\GitHub\\OktaKenkinsCI\\OktaKenkinsCI.csproj"
             }
           }
           
        stage('Build'){
           steps{
              bat "dotnet build C:\\Users\\Brenden\\Documents\\GitHub\\OktaKenkinsCI\\OktaKenkinsCI.csproj --configuration Releas'"
            }
         }
         
     }
  
 }

这给了我以下输出:

Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in C:\WINDOWS\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\JenkinsPipeline
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] git
The recommended git tool is: NONE
using credential 0b02e39b-17f0-4628-ba3d-24146ec7a469
 > git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url https://github.com/bellingboe/OktaKenkinsCI.git # timeout=10
Fetching upstream changes from https://github.com/bellingboe/OktaKenkinsCI.git
 > git.exe --version # timeout=10
 > git --version # 'git version 2.29.2.windows.3'
using GIT_ASKPASS to set credentials 
 > git.exe fetch --tags --force --progress -- https://github.com/bellingboe/OktaKenkinsCI.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
 > git.exe rev-parse "origin/master^{commit}" # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Restore packages)
Stage "Restore packages" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Clean)
Stage "Clean" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build)
Stage "Build" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
Finished: FAILURE

我的脚本中有什么错误吗?我真的不知道什么会失败,因为我根本没有看到任何错误。

标签: jenkinsgithubcontinuous-integrationjenkins-pipelinejenkins-plugins

解决方案


我想到了。我的主分支在 github 中被命名为“main”。

我有一个错字!


推荐阅读