【问题标题】:Jenkins declarative pipeline for simple basic code用于简单基本代码的 Jenkins 声明式管道
【发布时间】:2021-05-11 03:40:54
【问题描述】:

我正在尝试从 git 中获取代码,然后在 Jenkins 上运行它。目前,我正在 Windows 机器上运行 Jenkins。但是这段代码给了我一个错误“不是有效的阶段部分定义:”

pipeline {
        agent any
    
        stages {
            stage('Hello') {
               try
               {
                   git 'https://github.com/AnikQUPS/learning.git'
                   sh "python3 python.python"
               }
               catch(err)
               {
                   echo err
               }
            }
        }
    }

【问题讨论】:

标签: python jenkins jenkins-pipeline


【解决方案1】:

在声明式管道中,您需要将 try-catch 括在 script{} 块中。

所以,你的管道应该是这样的:

pipeline {
        agent any
    
        stages {
            stage('Hello') {
               steps {
                  script {
               try
               {
                   git 'https://github.com/AnikQUPS/learning.git'
                   sh "python3 python.python"
               }
               catch(err)
               {
                   echo err
               }
              }
             }
            }
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-12
    • 2021-01-15
    • 2017-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多