Jenkins Quick Start - Part 3 - Plugin Management and Builds

2018年04月27日


Manage Jenkins
Manage Plugins
在“Available” tab里搜索“SSH”,选中“SSH”,“Download now and install after restart"
选中“Restart Jenkins when installation is complete and no jobs are running"


Manage Jenkins
Manage Credentials
Jenkins
Global credentials (unrestricted)
Add Credentials

增加用户名jenkins及其对应密码。
Kind:Username with password
Username:jenkins
Password
Description


Add Credentials
Kind:SSH Username with private key
Username:jenkins
Private Key: From the key file /var/lib/jenkins/.ssh/id_rsa on the Jenkins master node, copy its content and paste here.
Description


Manage Jenkins
Configure System
SSH remote hosts
SSH sites
Add
Hostname: localhost
Port:22
Credentials:jenkins

Add
Hostname:10.0.0.x  # 使用内网IP
Port:22
Credentials:jenkins


MyBuilds (displayed as TestBuilds)
New Item
Enter an item name: RemoteLogViewer
Freestyle project
Build
Execute shell script on remote host using ssh
SSH site选择“jenkins@10.0.0.x:22”
Command:

sudo cat /var/log/messages


Jenkin Master node上需要先安装Git,否则会有以下报错:
Failed to connect to repository : Error performing command: git ls-remote -h https://github.com/latest123/mytest.git HEAD

[root@master ~]# yum install -y git

MyBuilds (TestBuilds)
New Item
MyGithubBuild
Freestyle project
Check the "GitHub project" checkbox
Project url: https://github.com/latest123/mytest.git
Source Code Management
Git
Repository URL: https://github.com/latest123/mytest.git

Save
Build Now

Result:SUCCESS


[root@master ~]# cd /var/lib/jenkins/workspace/MyBuilds/MyGithubBuild

[root@master MyGithubBuild]# ls -al
total 12
drwxr-xr-x. 3 jenkins jenkins   70 Jun  6 07:13 .
drwxr-xr-x. 4 jenkins jenkins   47 Jun  6 07:13 ..
drwxr-xr-x. 8 jenkins jenkins  162 Jun  6 07:13 .git
-rw-r--r--. 1 jenkins jenkins 2325 Jun  6 07:13 index.js
-rw-r--r--. 1 jenkins jenkins   45 Jun  6 07:13 README.md
-rw-r--r--. 1 jenkins jenkins 2069 Jun  6 07:13 template.js

[root@master MyGithubBuild]# cat README.md
# mytest
For temporary files needed for labs

[root@master MyGithubBuild]# cat index.js
'use strict';
const AWS = require('aws-sdk'),
docClient = new AWS.DynamoDB.DocumentClient({ region: 'us-east-1'
}),
generateHtml = require('./template'), acceptablePaths = ['status.html', 'status.json'], strings = {
title: "CloudFormation+Serverless Application Model Lab", notFound: "How'd you get here?",
badRequest: "I don't know what you want.",
      },success: "You've successfully deployed Lambda/API Gateway/DynamoDB!"
requestShould400 = event  > typeof event === 'undefined' || typeof event.pathParameters === 'undefined' ||
typeof event.pathParameters.request === 'undefined', requestShould404 = (event, acceptablePaths)  > acceptablePaths .indexOf(event.pathParameters.request) === -1,
      badRequest = event  > {
        const baseResponse = {
headers: {
};} "Content-Type": 'text/html'
if (requestShould400(event)) {
return Object.assign({}, baseResponse, {
            statusCode: 400,
body: generateHtml(strings.title, strings.badRequest) } });
if (requestShould404(event, acceptablePaths)) { return Object.assign({}, baseResponse, {
            statusCode: 404,
body: generateHtml(strings.title, strings.notFound) } });
      },return null;
goodRequest = (counter, fileName)  > { const payload = {
title: strings.title,
response: strings.success, },count: counter
          baseResponse = {
          },statusCode: 200
fileFormat = fileName.split('.')[1]; switch (fileFormat) {
case 'json':
return Object.assign({}, baseResponse, {
body: JSON.stringify(payload), headers: {
} "Content-Type": 'application/json'
});
case 'html':
return Object.assign({}, baseResponse, {
body: generateHtml(payload.title, payload.response, payload.
    count),
              headers: {
} "Content-Type": 'text/html' });
};}
exports.handler = (event, context, callback)  > {
if (badRequest(event)) {
context.s ucceed(badRequest(event));
} else {
const tableName = process.env.TABLE_NAME; doc Clie nt.g et({
            Key: {
            },id: 'requests'
TableName: tableName }).promise().then(data  > {
const counter = (!data.Item) ? 1 : data.Item.count + 1; doc Clie nt.p ut({
Item: {
id: 'requests',
                },count: counter
TableName: tableName
}).p ro mise()
.then(()  > context.succeed(goodRequest(counter, event.
pathParameters.r equest)))
.catch(err  > context.fail(err)) })
.catch(err  > context.fail(err)); }}

[root@master MyGithubBuild]# cd

[root@master ~]# mkdir -p /var/www/html

[root@master ~]# chown jenkins:jenkins /var/www/html


MyGithubBuild
Configure
Source Code Management
Additional Behaviours
Add
Checkout to a sub-directory
Local subdirectory for repo: /var/www/html

Save
Build Now


[root@master ~]# ls -al /var/www/html
total 12
drwxr-xr-x. 3 jenkins jenkins   70 Jun  6 07:31 .
drwxr-xr-x. 3 root    root      18 Jun  6 07:16 ..
drwxr-xr-x. 8 jenkins jenkins  162 Jun  6 07:31 .git
-rw-r--r--. 1 jenkins jenkins 2325 Jun  6 07:31 index.js
-rw-r--r--. 1 jenkins jenkins   45 Jun  6 07:31 README.md
-rw-r--r--. 1 jenkins jenkins 2069 Jun  6 07:31 template.js



Category: Jenkins Tags: public

Upvote


Downvote