jenkins shell 改为 pipeline
时间: 2023-09-25 21:15:34 浏览: 37
将 Jenkins 的 Shell 脚本转换为 Pipeline 可以提高可读性和可维护性。以下是一个简单的示例:
Shell 脚本:
```
#! /bin/bash
echo "Building project"
mvn clean install
echo "Deploying to server"
scp target/myapp.war user@server:/opt/tomcat/webapps/
```
转换为 Pipeline:
```
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building project'
sh 'mvn clean install'
}
}
stage('Deploy') {
steps {
echo 'Deploying to server'
sh 'scp target/myapp.war user@server:/opt/tomcat/webapps/'
}
}
}
}
```
在 Pipeline 中,我们可以使用更加直观的语法来定义构建流程,例如 stages、steps 等。同时,Pipeline 还提供了更多的功能,如并行执行、参数化构建等。