Update sandbox instructions
[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 ssh://<LFID>@gerrit.onap.org:29418/ci-management --recursive && scp -p -P 29418 \
29 <LFID>@gerrit.onap.org:hooks/commit-msg ci-management/.git/hooks/`
30
31 Make sure to sync global-jjb submodule using:
32
33 `git submodule update --init`
34
35 Once you successfully clone the repository, next step is to install JJB
36 (Jenkins Job Builder) in order to experiment with Jenkins jobs.
37
38 ### Execute the following commands to install JJB on your machine:
39
40 ```
41 cd ci-management
42 sudo apt-get install python-virtualenv
43 virtualenv onap_sandbox
44 source onap_sandbox/bin/activate
45 pip install jenkins-job-builder
46 jenkins-jobs --version
47 jenkins-jobs test --recursive jjb/
48 ```
49
50 ### Make a copy of the example JJB config file (in the builder/ directory)
51
52 Backup the jenkins.ini.example to jenkins.ini
53
54 `cp jenkins.ini.example jenkins.ini`
55
56 After copying the jenkins.ini.example, modify `jenkins.ini` with your
57 **Jenkins LFID username**, **API token** and **ONAP jenkins sandbox URL**
58
59 ```
60 [job_builder]
61 ignore_cache=True
62 keep_descriptions=False
63 include_path=.:scripts:~/git/
64 recursive=True
65
66 [jenkins]
67 user=jwagantall <Provide your Jenkins Sandbox username>
68 password= <Refer below steps to get API token>
69 url=https://jenkins.onap.org/sandbox
70 This is deprecated, use job_builder section instead
71 ignore_cache=True
72 ```
73 ### How to retrieve API token?
74 Login to the [Jenkins Sandbox](https://jenkins.onap.org/sandbox/), go to your user
75 page by clicking on your username. Click **Configure** and then click **Show API Token**.
76
77 To work on existing jobs or create new jobs, navigate to the `/jjb` directory where you
78 will find all job templates for the project.  Follow the below commands to test,
79 update or delete jobs in your sandbox environment.
80
81 ## To Test a Job:
82
83 After you modify or create jobs in the above environment, it's good practice
84 to test the job in sandbox environment before you submit this job to production CI environment.
85
86 `jenkins-jobs --conf jenkins.ini test jjb/ <job-name>`
87
88 **Example:** `jenkins-jobs --conf jenkins.ini test jjb/ sdc-master-verify-java`
89
90 If the job you’d like to test is a template with variables in its name, it must be
91 manually expanded before use. For example, the commonly used template `sdc-{stream}-verify-java`
92 might expand to `sdc-master-verify-java`.
93
94 A successful test will output the XML description of the Jenkins job described by the
95 specified JJB job name.
96
97 Execute the following command to pipe-out to a directory:
98
99 `jenkins-jobs --conf jenkins.ini test jjb/ <job-name> -o <directoryname>`
100
101 The output directory will contain files with the XML configurations.
102
103 ## To Update a job:
104
105 Ensure you’ve configured your `jenkins.ini` and verified it by
106 outputting valid XML descriptions of Jenkins jobs. Upon successful
107 verification, execute the following command to update the job to the
108 Jenkins sandbox.
109
110 `jenkins-jobs --conf jenkins.ini update jjb/ <job-name>`
111
112 **Example:** `jenkins-jobs --conf jenkins.ini update jjb/ sdc-master-verify-java`
113
114 ## Trigger jobs from Jenkins Sandbox:
115
116 Once you push the Jenkins job configuration to the ONAP Sandbox environment,
117 run the job from Jenkins Sandbox webUI. Follow the below process to trigger the build:
118
119 Step 1: Login into the [Jenkins Sandbox WebUI](https://jenkins.onap.org/sandbox/)
120
121 Step 2: Click on the **job** which you want to trigger, then click
122 **Build with Parameters**, and finally click **Build**.
123
124 Step 3: Verify the **Build Executor Status** bar and make sure that the build is triggered
125 on the available executor. In Sandbox you may not see all platforms build executors and
126 you don't find many like in production CI environment.
127
128 Once the job is triggered, click on the build number to view the job
129 details and the console output.
130
131 ## To Delete a Job:
132
133 Execute the following command to Delete a job from Sandbox:
134
135 `jenkins-jobs --conf jenkins.ini delete jjb/ <job-name>`
136
137 **Example:** `jenkins-jobs --conf jenkins.ini delete jjb/ sdc-master-verify-java`
138
139 The above command would delete the `sdc-master-verify-java` job.
140
141 ## Modify an Existing Job:
142
143 In the ONAP Jenkins sandbox, you can directly edit or modify the job configuration
144 by selecting the job name and clicking on the **Configure** button. Then, click the
145 **Apply** and **Save** buttons to save the job.
146
147 However, it is recommended to simply modify the job in your terminal and then follow
148 the previously described steps in **To Test a Job** and **To Update a Job** to perform
149 your modifications.
150
151 ## More online documentation:
152
153 https://docs.openstack.org/infra/jenkins-job-builder/