未加星标

Setup Jenkins for Go Project

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二03 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

Jenkins is a powerful automation tool, it provides hundreds of plugins to support building, deploying and automating any project. So does for Go! I would like to follow an example of creating a task for CoreDNS to illustrate what should be paid attention to. This is a basic tutorial for beginners that starts from setting up a new Jenkins service from scratch.

0. Prerequisites

According to Jenkins official documentation ,

Jenkins requires Java7 or above to function. Java8 is recommended. Jenkins requires a fair amount of memory to operate well. Smaller installations should start around 256MB-1GB.

1. Install Jenkins Container on CentOS (Preferred)

I highly recommend to install Jenkins with Container, it makes life easier if you want to deploy the same Jenkins instance to a new machine. If you want to install Jenkins directly in a VM, please skip this section and checkInstall Jenkins Directly on CentOS (Optional).

1.1 Get Docker CE for CentOS

You may refer to this guide to get Docker CE for CentOS . It is recommended to install from package manager. Don’t forget to setup Docker as a non-root user and configure Docker to start on boot, which are listed in Post-installation steps for linux .

1.2 Launch Jenkins Container

Pull the official jenkins image from Docker repository,

# If you want to use official build of jenkins image docker pull jenkins/jenkins # It is recommended to use my Dockerfile # It has more tools installed for Go project build, like `make`. git clone https://github.com/zp-j/docker.git cd docker && docker build -t zhipj/jenkins .

Run a container using this image and map data directory from the container to the host; e.g in the example below /var/jenkins_home from the container is mapped to jenkins/ directory from the current path on the host. Jenkins 8080 port is also exposed to the host as 49001 .

# Launch official docker image docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home -t jenkins/jenkins # Launch customized docker image docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home -t zhipj/jenkins

If you are using Azure VM, don’t forget to add inbound security rules:


Setup Jenkins for Go Project

PAY ATTENTION

Make sure local jenkins/ directory can be accessed by Docker, otherwise it would lead to launch failed due to no write permission. More details can be found here: Go Plugin for Jenkins .

You can simply change that:

chown 1000 jenkins

1.3 Jenkins Users Setup

Once container is launched, you should be able to access Jenkins now from your browser. For the first login, you are required to enter the initial password for user admin , you can find it either from docker log,

$ docker logs [container_id] Aug 09, 2017 3:22:03 PM jenkins.install.SetupWizard init INFO: ************************************************************* ************************************************************* ************************************************************* Jenkins initial setup is required. An admin user has been created and a password generated. Please use the following password to proceed to installation: 695zzz4yyyy04aaaxxx9a1c3b1XXX576 This may also be found at: /var/jenkins_home/secrets/initialAdminPassword ************************************************************* ************************************************************* *************************************************************

Or, you can check your local file,

$ cat ~/jenkins/secrets/initialAdminPassword 695zzz4yyyy04aaaxxx9a1c3b1XXX576

After you login, you would see a welcome message like this


Setup Jenkins for Go Project
Don’t forget to change your admin’s password as well as create new users. 2. Install Jenkins Directly on CentOS (Optional)

If you are looking for the guide of installing Jenkins on a bare metal, here is the steps of installation on CentOS 7.3.

2.1 Install a Sun-compatible Java $ yum remove java $ yum install java-1.7.0-openjdk $ java -version java version "1.7.0_79" OpenJDK Runtime Environment (rhel-2.5.5.1.el6_6-x86_64 u79-b14) OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode) 2.2 Install Jenkins $ sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo $ sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key $ sudo yum install jenkins 2.3 Start/Stop $ sudo systemctl enable jenkins $ sudo systemctl start jenkins $ sudo systemctl stop jenkins 2.4 Important Note With the help of systemctl , Jenkins can be launched as a daemon on startup. The jenkins user is created to run this service. If you change this to a different user via the config file, you must change the owner of /var/log/jenkins , /var/lib/jenkins , and /var/cache/jenkins . Log file will be placed in /var/log/jenkins/jenkins.log . Check this file if you are troubleshooting Jenkins. /etc/sysconfig/jenkins will capture configuration parameters for the launch. By default, Jenkins listen on port 8080 . Access this port with your browser to start configuration. Note that the built-in firewall may have to be opened to access this port from other computers. (See http://www.cyberciti.biz/faq/disable-linux-firewall-under-centos-rhel-fedora/ for instructions how to disable the firewall permanently) 2.5 Optional

Install some common tools to make troubleshooting easy.

sudo yum install epel-release sudo yum install vim git htop bmon tmux

If you are using Azure VM, don’t forget to add inbound security rules:


Setup Jenkins for Go Project
3. Setup Go Build Environment 3.1 Install Golang Plugin Get the Go Plugin for Jenkins , [Manage Jenkins] -> [Manage Plugins] -> [Available] -> [Go Plugin] . After the installation of plugin, restart your container.

Pick Go 1.7.6 , there is configuration issue between Go 1.8 and glide .

3.2 Add New Build Item

Create new freestyle project, in the section Source Code Management , give your git repository and credential if needed, pick the right branch to build. In Additional Behaviours , choose to check out to a sub directory.


Setup Jenkins for Go Project
$WORKSPACE/../src/github.com/coredns/coredns

By default your repo will be checked out to $WORKSPACE/coredns , it does not follow the package structure of a normal Go project. Therefore, we move it to the right place beneath $GOPATH .

In Build Environment section, check Set up Go programming language tools , pick the right Go version that was marked when you installed go plugin. In Build section, choose to Execute shell , paste the script below to the input box. It creates an environment variable $GOPATH , which contains the repository and all its dependencies.

# Create GOPATH export GOPATH=$WORKSPACE/.. export PATH=$GOPATH:$PATH # Run make to perform the build cd $GOPATH/src/github.com/coredns/coredns && make coredns

Click Save , start a build, check its console output and wait a second. Voilà!

... github.com/coredns/coredns/vendor/k8s.io/client-go/1.5/tools/clientcmd github.com/coredns/coredns/middleware/kubernetes github.com/coredns/coredns/middleware/autopath github.com/coredns/coredns/core github.com/coredns/coredns/coremain github.com/coredns/coredns Finished: SUCCESS

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

主题: DockerJavaLinuxUCSUTI
分页:12
转载请注明
本文标题:Setup Jenkins for Go Project
本站链接:http://www.codesec.net/view/561383.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(46)