@@ -4,26 +4,26 @@ title: Continuous Integration with Jenkins
44tagline :
55---
66
7- Jenkins is an automation server for running continuous integration tests. The SD2E project uses
8- [ Jenkins] ( http://jenkins.sd2e.org/ ) for continuous integration (CI) to ensure
9- any changes that have been made to apps do not break their
10- core functionality. It is now standard practice to set up CI for all Agave apps.
11- This will ensure your deployed app is always up to date with the master branch
12- of your git repo, and it will alert you if jobs are not working. This guide will
13- help you integrate continuous integration testing into any app you would like to
14- deploy, but is not meant to be a replacement for the [ Jenkins documentation] ( https://jenkins.io/doc/ ) .
15-
16-
7+ Jenkins is an automation server for running continuous integration tests. The
8+ SD2E project uses [ Jenkins] ( http://jenkins.sd2e.org/ ) for continuous integration
9+ (CI) to ensure any changes that have been made to apps do not break their core
10+ functionality. It is now standard practice to set up CI for all Agave apps. This
11+ will ensure your deployed app is always up to date with the master branch of
12+ your git repo, and it will alert you if jobs are not working. This guide will
13+ help you integrate CI testing into any app you would like to deploy, but is not
14+ meant to be a replacement for the
15+ [ Jenkins documentation] ( https://jenkins.io/doc/ ) .
1716
1817
1918
2019<br >
21- #### The Jenkins File
22- The Jenkins file defines the stages of your Jenkins job and defines the environment
23- variables for that job. The Jenkins file is written in Groovy, and should be located
24- at the top-level directory for your app. For the previous fastqc app example, the
25- Jenkins file would be in the ` ~/fastqc-app/ ` directory. Here is an example of the Jenkins
26- file for the fastqc app:
20+ #### The Jenkins file
21+
22+ The Jenkins file defines the stages and environment variables of your Jenkins
23+ job. The Jenkins file is written in [ Groovy] ( http://groovy-lang.org/ ) , and
24+ should be located at the top-level directory for your app. For the previous
25+ FastQC app example, the Jenkins file would be in the ` ~/fastqc-app/ ` directory.
26+ Here is an example of a Jenkins file for the FastQC app:
2727
2828```
2929#!groovy
@@ -68,14 +68,12 @@ pipeline {
6868 stage('Run a test job') {
6969 steps {
7070 sh "run-test-job deploy-${AGAVE_USERNAME}-job.json ${AGAVE_JOB_TIMEOUT}"
71- // Assumption here is that run_test_job generates a job.jobid file
72- // Might be smart to check if it exists if we want to bundle this step with previous in a step
7371 sh "get-test-job-outputs deploy-${AGAVE_USERNAME}-job.json.jobid ${AGAVE_JOB_GET_DIR}"
7472 }
7573 }
7674 stage('Validate results') {
7775 steps {
78- sh "python -m pytest tests/validate_job --job-directory ${AGAVE_JOB_GET_DIR}"
76+ sh "python -m pytest tests/validate-job --job-directory ${AGAVE_JOB_GET_DIR}"
7977 }
8078 }
8179 }
@@ -91,51 +89,73 @@ pipeline {
9189
9290```
9391
94- For the most part, you won't need to change any of the environment variables in
95- the groovy file. All the Jenkins jobs will run as the ` sd2etest ` user. You will
96- need to define the input data for your app, see the ` AGAVE_DATA_URI ` field. If
97- your test data is located in your private storage system ` data-tacc-work-username ` ,
98- you'll need to give the ` sd2etest ` user access to that system with the following
99- CLI command:
92+ Copy and paste the above text into a file called ` Jenkinsfile ` in the top level
93+ of your ` ~/fastqc-app/ ` directory.
94+
95+ The file is divided into three sections: ` environment ` , ` stages ` , and ` post ` .
96+ The ` environment ` section defines environment variables needed by the Jenkins
97+ server to run the test job. Most of the variables in this section are specific
98+ to the Jenkins server and should be left alone. The ` CONTAINER_REPO ` and
99+ ` CONTAINER_TAG ` variables should, collectively, point to a "test" repository
100+ location so that the versioned app is not overwritten. It is good practice to
101+ use the app name (e.g. "` fastqc ` ") as the ` CONTAINER_REPO ` , and "` test ` " as the
102+ ` CONTAINER_TAG ` .
103+
104+ You may also need to change ` AGAVE_DATA_URI ` if your data is located on some
105+ other system or in a different path. Also note that if your test data is located
106+ in your private storage system, ` data-tacc-work-username ` , you will need to grant
107+ ` READ ` access to the ` sd2etest ` user with the following command:
108+
100109```
101110systems-roles-addupdate -u sd2etest -r USER data-tacc-work-username
102111```
103112
104- The stages of a Jenkins test will also remain largely unchanged. You will always
105- need to
113+ The ` stages ` section of the Jenkins file will also remain largely unchanged. You
114+ will typically need the following sections:
1061151 . ` Create Oauth client `
1071162 . ` Build container `
1081173 . ` Deploy to TACC.cloud `
1091184 . ` Run a test job ` , and
1101195 . ` Validate results `
111120
112- To validate your results, you'll need to define pytests that will be run to verify your app is functional.
113- For the fastqc app, navigate to the tests directory ` ~/fastqc-app/tests ` , and create
114- a new directory called "validate_job":
121+ The first four steps depend on scripts that exist on the Jenkins server, and
122+ should work the same for most apps. The final step must be written by the app
123+ developer, and will be different from app to app. More details on this step are
124+ included in the next section below.
125+
126+ Finally, the ` post ` section uses one more script on the Jenkins server to clean
127+ up the session and exit the Jenkins test. This section should not change.
128+
129+ <br >
130+ #### Validating results with pytests
131+
132+ To validate your results, you will need to define pytests that will be run to
133+ verify your app is functional. For the FastQC app, navigate to the tests
134+ directory ` ~/fastqc-app/tests ` , and create a new sub-directory called
135+ ` validate-job ` :
115136```
116137cd ~/fastqc-app/tests
117- mkdir validate_job
118- cd validate_job
138+ mkdir validate-job
139+ cd validate-job
119140```
120141
121- Create two pytests in that directory, ` conftest.py ` and ` test_files.py ` . You can copy/paste
122- these two examples,
123- conftest.py:
142+ Create two pytests in that directory, ` conftest.py ` and ` test_files.py ` . You can
143+ copy and paste these two examples directly:
144+
145+ ` conftest.py ` :
124146```
125147import pytest
126148
127-
128149def pytest_addoption(parser):
129150 parser.addoption("--job-directory", action="store", default="job_output",
130151 help="Directory containing output to evaluate")
131152
132-
133153@pytest.fixture
134154def job_directory(request):
135155 return request.config.getoption("--job-directory")
136156```
137157
138- test_files.py:
158+ ` test_files.py ` :
139159```
140160'''Test for specific files existence in a directory'''
141161import pytest
@@ -160,9 +180,9 @@ def test_files(job_directory,file_list):
160180 raise IOError("Couldn't stat {}".format(f))
161181```
162182
163- The conftest.py adds a --job-directory option to pytest, this points to the location of
164- the output files that are created by running your app. The pytest test_files.py checks if
165- files exist and are greater than 0 bytes.
183+ The ` conftest.py ` adds a ` --job-directory ` option to pytest, this points to the
184+ location of the output files that are created by running your app. The pytest
185+ ` test_files.py ` checks if files exist and are greater than 0 bytes.
166186
167187If you are creating pytests for a different app, you can simply change the output
168188file names in line 7 of ` test_files.py ` , to the file names that are output by your app:
@@ -173,21 +193,22 @@ file names in line 7 of `test_files.py`, to the file names that are output by yo
173193 (['reads1_fastqc.html', 'reads1_fastqc.zip'])
174194])
175195```
176- In this example, Jenkins is testing for the existence of reads1_fastqc.html and
177- reads1_fastqc.zip, which indicate that the fastqc app ran successfully.
196+ In this example, Jenkins is testing for the existence of ` reads1_fastqc.html `
197+ and ` reads1_fastqc.zip ` , which indicate that the FastQC app ran successfully.
178198
179199<br >
180- #### Setting up the Jenkins Server
181- Now that you've created a groovy file and defined pytests,
182- you'll need to add your repo to the Jenkins server and define when it should
183- run tests. We typically have the server run a test every time a changed is pushed
184- to the master branch, or anytime a merge request to the master branch is made. It
185- may also be a good idea to schedule weekly or monthly builds to ensure you app
200+ #### Setting up the Jenkins server
201+
202+ Now that you have created a groovy file and defined pytests, you will need to
203+ add your repo to the Jenkins server and define when it should run tests. We
204+ typically have the server run a test every time a changed is pushed to the
205+ master branch, or anytime a merge request to the master branch is made. It may
206+ also be a good idea to schedule weekly or monthly builds to ensure your app
186207continues working even when no changes have been made to the source repo.
187208
188209To set up Jenkins tests for your app, follow the instructions in this video tutorial:
189- <iframe width =" 560 " height =" 315 " src =" https://www.youtube.com/embed/XfhgGZ0CAPw " frameborder =" 0 " allow =" autoplay; encrypted-media " allowfullscreen ></iframe >
190210
211+ <iframe width =" 560 " height =" 315 " src =" https://www.youtube.com/embed/XfhgGZ0CAPw " frameborder =" 0 " allow =" autoplay; encrypted-media " allowfullscreen ></iframe >
191212
192213
193214---
0 commit comments