Jenkins Coding使用笔记

1
2
#From Ubuntu
docker exec -ti jenkins /bin/bash
1
2
#From Docker
ssh-keygen

域名: 如填写 coding

描述: 如填写:coding仓库

描述和Username 我都是填写 coding_jenkins
Private key: 填入Jenkins 容器的私钥

1
2
3
4
5
6
#From Docker jenikins Container

#生成密钥
ssh-keygen
#查看公钥
cat /var/jenkins_home/.ssh/id_rsa

将公钥加入到coding个人资料中的公钥中,这样就可以访问当前工作空间的所有代码仓库了


Jenkins pipeline git parameter

Plugin: Git parameter

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
pipeline {
agent any
environment {
def DEPLOY_GIT_SSH_URL = "http://localhost:10011/test.git"
}
parameters {
gitParameter name: 'TAG',
type: 'PT_TAG',
defaultValue: 'master'
}
stages {
stage('pull code') {
steps {
checkout([$class: 'GitSCM', branches: [[name: "${params.TAG}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'fa16d707-070c-4462-9089-965bad493dd1', url: "${DEPLOY_GIT_SSH_URL}"]]])
}
}


stage('publish to ten servers') {
steps {

script {
def SERVER_NODES = ["server1","server2"]
for (server_node in SERVER_NODES){
echo "部署服务器 ${server_node} 中"
sshPublisher(publishers: [sshPublisherDesc(configName: "${server_node}", transfers: [sshTransfer(cleanRemote: false, excludes: 'Jenkinsfile,README.md,CHANGELOG.md', execCommand: '''chmod 755 /var/www/html/test
chmod 755 /var/www/html/test/* -R''', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/var/www/html/test/', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '**/*')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}

}
}
}
}

其中 credentialsId 是验证凭证id,可以在 系统管理 -> 凭据,就会看到 凭据列表,其中列表的 唯一标识中看到

SERVER_NODES 数组中 元素是在 Jinkins 系统配置中, Publish over SSHSSH Server 中填写的名称(Name)。

References