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