编写脚本并上传git仓库

首先将pipeline脚本写好上传至git仓库

test-demo1.File 文本简单输出 helloworld

pipeline {
agent any
stages {
stage('print helloworld') {
steps {
echo "helloworld"
}
}
}
}

jenkins执行远程git仓库jenkinsfile

在jenkins机器上生成ssh key

ssh-keygen -t rsa -C "root@example.com"

将公钥id_rsa.pub内容复制到gitlab上,图片中key位置中

在jenkins上添加凭据,将私钥id_rsa内容复制进图片中key位置

在jenkins中创建流水线,并配置

执行流水线任务