Merge "Add Jenkins job for base amd common images"
[ci-management.git] / Sandbox_Setup.md
1 ## ONAP Jenkins Sandbox Process:
2
3 ONAP Jenkins Sandbox provides you Jenkins Job testing/experimentation environment
4 that can be used before pushing job templates to the production
5 [Jenkins](https://jenkins.onap.org).
6
7 It is configured similar to the ONAP [ci-management] production instance;
8 however, it cannot publish artifacts or vote in Gerrit. Be aware that this is a
9 test environment, and as such there a limited allotment of minions to test on
10 before pushing code to the ONAP repos.
11 Keep the following points in mind prior to beginning work on ONAP Jenkins Sandbox
12 environment:
13
14 - Jobs are automatically deleted every weekend
15 - Committers can login and configure Jenkins jobs in the sandbox directly
16 - Sandbox jobs CANNOT perform any upload tasks
17 - Sandbox jobs CANNOT vote on Gerrit
18 - Jenkins nodes are configured using ONAP openstack VMs and you can not access
19   these VMs directly.
20
21 Before you proceed further, ensure you have a Linux Foundation ID (LFID), which is
22 required to access Gerrit & Jenkins. Also, to get an access to Sandbox environment
23 please send email to helpdesk@onap.org (LF helpdesk team)
24
25 To download **ci-management**, execute the following command to clone the
26 **ci-managment** repository.
27
28 `git clone https://gerrit.onap.org/r/ci-management && (cd ci-management && curl -Lo \
29 $(git rev-parse --git-dir)/hooks/commit-msg https://gerrit.onap.org/r/tools/hooks/commit-msg; \
30 chmod +x $(git rev-parse --git-dir)/hooks/commit-msg)`
31
32 Make sure to sync global-jjb submodule using:
33
34 `git submodule update --init`
35
36 Once you successfully clone the repository, next step is to install JJB
37 (Jenkins Job Builder) in order to experiment with Jenkins jobs.
38
39 ### Execute the following commands to install JJB on your machine:
40
41 ```
42 cd ci-management
43 sudo apt-get install python-virtualenv
44 virtualenv onap_sandbox
45 source onap_sandbox/bin/activate
46 pip install jenkins-job-builder
47 jenkins-jobs --version
48 jenkins-jobs test --recursive jjb/
49 ```
50
51 ### Make a copy of the example JJB config file (in the builder/ directory)
52
53 Backup the jenkins.ini.example to jenkins.ini
54
55 `cp jenkins.ini.example ~/.config/jenkins_jobs/jenkins_jobs.ini`
56
57 After copying the jenkins.ini.example, modify `jenkins.ini` with your
58 **Jenkins LFID username**, **API token** and **ONAP jenkins sandbox URL**
59
60 ```
61 [job_builder]
62 ignore_cache=True
63 keep_descriptions=False
64 include_path=.:scripts:~/git/
65 recursive=True
66
67 [jenkins]
68 user=jwagantall <Provide your Jenkins Sandbox username>
69 password= <Refer below steps to get API token>
70 url=https://jenkins.onap.org/sandbox
71 This is deprecated, use job_builder section instead
72 ignore_cache=True
73 ```
74 ### How to retrieve API token?
75 Login to the [Jenkins Sandbox](https://jenkins.onap.org/sandbox/), go to your user
76 page by clicking on your username. Click **Configure** and then click **Add new Token**.
77 After that specify a token name (optional) and click on **Generate** to generate and show
78 new token. Please note down your token and store it securely.
79
80 To work on existing jobs or create new jobs, navigate to the `/jjb` directory where you
81 will find all job templates for the project.  Follow the below commands to test,
82 update or delete jobs in your sandbox environment.
83
84 ## To Test a Job:
85
86 After you modify or create jobs in the above environment, it's good practice
87 to test the job in sandbox environment before you submit this job to production CI environment.
88
89 `jenkins-jobs test jjb/ <job-name>`
90
91 **Example:** `jenkins-jobs test jjb/ sdc-master-verify-java`
92
93 If the job you’d like to test is a template with variables in its name, it must be
94 manually expanded before use. For example, the commonly used template `sdc-{stream}-verify-java`
95 might expand to `sdc-master-verify-java`.
96
97 A successful test will output the XML description of the Jenkins job described by the
98 specified JJB job name.
99
100 Execute the following command to pipe-out to a directory:
101
102 `jenkins-jobs test jjb/ <job-name> -o <directoryname>`
103
104 The output directory will contain files with the XML configurations.
105
106 ## To Update a job:
107
108 Ensure you’ve configured your `jenkins.ini` and verified it by
109 outputting valid XML descriptions of Jenkins jobs. Upon successful
110 verification, execute the following command to update the job to the
111 Jenkins sandbox.
112
113 `jenkins-jobs update jjb/ <job-name>`
114
115 **Example:** `jenkins-jobs update jjb/ sdc-master-verify-java`
116
117 ## Trigger jobs from Jenkins Sandbox:
118
119 Once you push the Jenkins job configuration to the ONAP Sandbox environment,
120 run the job from Jenkins Sandbox webUI. Follow the below process to trigger the build:
121
122 Step 1: Login into the [Jenkins Sandbox WebUI](https://jenkins.onap.org/sandbox/)
123
124 Step 2: Click on the **job** which you want to trigger, then click
125 **Build with Parameters**, and finally click **Build**.
126
127 Step 3: Verify the **Build Executor Status** bar and make sure that the build is triggered
128 on the available executor. In Sandbox you may not see all platforms build executors and
129 you don't find many like in production CI environment.
130
131 Once the job is triggered, click on the build number to view the job
132 details and the console output.
133
134 ## To Delete a Job:
135
136 Execute the following command to Delete a job from Sandbox:
137
138 `jenkins-jobs delete jjb/ <job-name>`
139
140 **Example:** `jenkins-jobs delete jjb/ sdc-master-verify-java`
141
142 The above command would delete the `sdc-master-verify-java` job.
143
144 ## Modify an Existing Job:
145
146 In the ONAP Jenkins sandbox, you can directly edit or modify the job configuration
147 by selecting the job name and clicking on the **Configure** button. Then, click the
148 **Apply** and **Save** buttons to save the job.
149
150 However, it is recommended to simply modify the job in your terminal and then follow
151 the previously described steps in **To Test a Job** and **To Update a Job** to perform
152 your modifications.
153
154 ## More online documentation:
155
156 https://docs.openstack.org/infra/jenkins-job-builder/