配置环境依赖:
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-
stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install epel-release # repository that provides 'daemonize'
yum install java-11-openjdk-devel
yum install jenkins
启动jenkins:
/etc/init.d/jenkins start
查看jenkins密码:
cat /var/lib/jenkins/secrets/initialAdminPassword
添加gitlab密钥:
红框需要填写,id会自动生成。?
新建一个流水线项目
把下面的代码复制到此处
pipeline {
agent any
stages {
stage('初始化环境') {
steps {
echo '初始化环境'
}
}
stage('检测环境') {
steps {
sh '''java -version
mvn -v
git version'''
}
}
stage('拉取代码') {
steps {
echo '拉取代码'
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: '438217f7-c1e5-4b30-a3be-3a60f2b98040', url: 'http://47.104.19.146/qushen/testlog.git']]])
}
}
stage('编译构建') {
steps {
echo '编译构建'
sh label: '', script: 'mvn clean package'
}
}
stage('项目部署') {
steps {
echo '项目部署'
sh 'cd target/ && pwd && java -jar jenkins.jar'
}
}
}
}
修改checkout内容:进入流水线语法,选择checkout,配置git地址,添加刚才的密钥,生成流水线脚本,修改上面的文字,然后保存
构建即可。
注意jenkins默认构建项目时间是十分钟,如果超时的话会报错,可以调整一下超时时间。
checkout poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'CheckoutOption', timeout: 58], [$class: 'CloneOption', noTags: false, reference: '', shallow: false, timeout: 60]], userRemoteConfigs: [[credentialsId: '438217f7-c1e5-4b30-a3be-3a60f2b98040', url: 'http://xxxxxxx/qushen/link-ui.git']]]
源码下载位置:
cd /var/lib/jenkins/workspace/
|