-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
71 lines (65 loc) · 2.67 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
pipeline {
agent any
stages {
stage('fetch code') {
steps {
git branch: 'hexo', credentialsId: 'jenkins_docker_ssh', poll: false, url: '[email protected]:screw-hand/screw-hand.github.io.git/'
}
}
stage('build') {
steps {
nodejs('v14.21.3(mirror)') {
sh '''
npm config list;
yarn -v;
yarn
'''
}
}
}
stage('deploy') {
steps {
nodejs('v14.21.3(mirror)') {
sh '''
eval `ssh-agent -s`
ssh-add /var/jenkins_home/.ssh/jenkins_docker_ssh;
ssh-add /var/jenkins_home/.ssh/screwhand;
git config --global user.email "[email protected]"
git config --global user.name "jenkins-boot"
yarn clean;
yarn deploy;
tar -zcvf docker.tar.gz docker;
tar -zcvf blog.tar.gz public;
'''
}
sshPublisher(publishers: [sshPublisherDesc(configName: 'screwhand_aliyun', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: ''' cd /root/screw-hand;
tar -zxvf docker.tar.gz 2> /dev/null;
cp -r docker/* .;
rm -rf docker/;
docker rmi screw-hand_nginx;
docker stop screw-hand_nginx;
docker rm screw-hand_nginx;
docker build -t screw-hand_nginx .;
docker-compose up -d;
docker images;
docker ps;
ls -last;''', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/root/screw-hand', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'docker.tar.gz')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
sshPublisher(publishers: [sshPublisherDesc(configName: 'screwhand_aliyun', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: ''' cd /root/screw-hand;
cp -r blog old-blog;
tar -zxvf blog.tar.gz 2> /dev/null;
cp -r public/* blog/;
rm -rf public;
ls -last;''', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/root/screw-hand', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'blog.tar.gz')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
}
post {
always {
emailext(
body: '${FILE,path="email.html"}',
subject: '${BUILD_STATUS}:${ENV, var="JOB_NAME"}-第${BUILD_NUMBER}次构建日志',
to: '[email protected]'
)
}
}
}