用于简单基本代码的 Jenkins 声明式管道

时间:2021-05-11 03:40:54

标签: python jenkins jenkins-pipeline

我正在尝试从 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
               }
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

在声明式管道中,您需要将 try-catch 括在脚本块中。

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

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