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