Set up a linux jenkins portable environment.

Source: Internet
Author: User

Set up a linux jenkins portable environment.

1: Background

Project: android.

Project requirement: create a website for the product manager (hereinafter referred to as PM) to configure the service plug-in required for the apk, package out the package (including: apk, documentation, demo, etc) to the vendor and record information such as package.

Simple text description of the project design scheme:

PHP is used as the server development language, nginx is used as the server, mysql database is used to store data, and jenkins is used as an auxiliary tool for continuous construction.

The simple architecture is as follows:

The packaging process is as follows:

2: jenkins Introduction

Jenkins is an open-source software project designed to provide an open and easy-to-use software platform that enables continuous software integration. To put it bluntly, it is essentially a web project. It provides functions such as creating a packaging project, pulling a project from svn, and executing a script. Download jenkins from the official website and you will get a jenkins. war file. The. war file format is the self-decompressed file format when the project in the tomcat service is released.

Installation Method: Install jdk 1.4 or above first:The second type is generally recommended, which is relatively stable.

1: You can decompress the file using java-jar jenkins. war, and then enter locathost: 8080 in the browser to open the jenkins homepage.

2: Move the jenkins. war file to the webapps directory of tomcat and run tomcat. The. war file is automatically decompressed into the jenkins folder. Visit: localhost: 8080/jenkins to open the jenkins homepage.

3. Environment setup and Configuration

The machine is a linux system. The Environment involved in the setup process is as follows:

1: jdk environment, more than 1.4 is required.

2: install tomcat

3: Install jenkins, download the jenkins. war package, and copy it to the webapps directory of tomcat.

4: install and configure the android environment and provide various android-related commands in the packaging script.

5. Install ant and run the ant function (the ant script used for android apk packaging ).

6: Configure svn.

After the build, you need to ensure portability, that is, replace the machine, copy a folder to the new machine, and execute a script. To do this, you have the following directory structure (the directory names can be set by yourself, and the red part is the key ):

1: Put all the files in the/data/jenkins directory of the linux root directory and mount the/data directory to a separate hard disk.

2: All environment variable configurations must be placed in the/data/jenkins/. bashrc script, and The. bashrc script must be configured in the startup execution list.

3: The jenkins project has a corresponding working directory, which is mainly used to save building records and project files pulled by svn. The working file name is generally. jenkins. You need to configure it to the/data/jenkins directory. The directory address can be viewed on the jenkins homepage, and a prompt is displayed for configuration.

 

3.1: install java jdk

Download the compressed package of java jdk 1.6 or later, decompress it to the/data/jenkins/java_xxx directory, and configure the environment variables in/data/jenkins /. add code to the bashrc file.

1: export JAVA_HOME =/data/jenkins/java_xxxx. This directory is mainly used for the classpath and path environment variables and is also provided to some third-party software, such as tomcat.

2: Configure classpath for Class search, which is related to import and package. Due to the complexity of the configuration, sun can also run java projects without configuration.

Export CLASSPATH =.: $ JAVA_HOME/dt. jar: $ JAVA_HOME/tool. jar;

3: Configure path and path to specify directories. commands in these directories can be directly run by users. For example, you can directly run java-version by configuring the bin directory of jdk.

Export PATH = $ JAVA_HOME/bin: $ JAVA_HOME/lib: $ PATH;

After the configuration is complete, run java-version to check whether the configuration is correct.

3.2: install tomcat

Download the zip package of tomcat 7.0 or later and decompress it to the/data/jenkins/tomcat_xxx directory. Execute tomcat_xxx/bin/startup. sh and then access localhost: 8080 to check whether the operation is normal.

After running properly, you need to add it to the auto-START process at startup, in the etc/init. d To create a tomcat script. Run/data/jenkins/first /. bashrc script, and then start startup in tomcat. sh. For more information about the code, see.

3.3: Install jenkins

Download jenkins. war, copy it to the/tomcat_xxx/webapps directory, configure the environment variables, and add them to/data/jenkins/. bashrc.

Export JENKINS_HOME =/data/jenkins/. jenkins is mainly configured with the jenkins data file directory, which stores each build record, logs, and files pulled by svn.

Then open localhost: 8080/jenkins/configure, configure the workspace directory (which stores the files pulled by svn) and the build space directory,

3.4: Install the android Environment

Download the android sdk, copy it to the/data/jenkins/directory, name it android-sdk, configure the environment variables, and add the following to/data/jenkins/. bashrc:

Export ANDROID_SDK_HOME =/data/jenkins/android-sdk, which mainly specifies the android root directory.

Export PROGUARD_HOME =/data/jenkins/android-sdk/tools/proguard, which is mainly used for obfuscation in packaging.

3.5: Install ant

Download the ant compressed package, decompress the package to/data/jenkins/ant-xxxx, configure the environment variables, and add the following to/data/jenkins/. bashrc:

Export PATH =/data/jenkins/ant-xxx/bin: $ PATH

3.6: Set svn

Jenkins usually comes with svn. Open the jenkins homepage, localhost: 8080/jenkins, create a new project, set the svn address in the svn column, click authorize, enter the user name and password, and save. You do not need to perform svn authorization for future packaging, so that automatic packaging can be realized.

After the setting is successful, you also need to go to the/data/jenkins/directory, execute svn info and add your working directory for authorization, and save it forever.

4: jenkins api

Jenkins provides interface-based operations and APIs, which can be called by other platforms. In my project, the server sends a command to jenkins through jenkins api to create a project, delete a project, and obtain the project status.

Api view url: https://wiki.jenkins-ci.org/display/jenkins/remote?access=api.

5. Notes

1: All environment configurations are in data/jenkins/. bashrc. bashrc needs to be automatically started upon startup and can be put into etc/init. d/tomcat for execution.

2: When installing the android sdk, check whether it matches the linux system. If the 64-bit system is 32-bit, An Exception error occurs during ant packaging. The system-level command is missing, of course, you can install them one by one.

3: The commands referenced in the ant script must correspond to the android sdk directory and jdk directory. Otherwise, the command cannot be found.

6: yy

This is the first time I wrote a blog. It feels really good and helpful to myself. It is not a good place to write. You are welcome to give your comments.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.