02_create-sample-project.md 3.06 KB
Newer Older
## Exercise 2: Create a new project ##
Tony Wildish's avatar
Tony Wildish committed
2 3 4

### Objective ###

5 6 7 8 9 10 11 12 13 14 15
Create a new project and import the sample code, see the build process it triggers.

### Create the project and upload the code, watch the build fail ###

- In the browser, click on **Projects** -> **Your projects**, from the top-left of the window.
- Click 'New Project', on the top-right
- Give the project a name, e.g. 'gitlab-101' or 'my-test-project'
  - add a description if you like, e.g. a reference to this tutorial
  - set the project visibility to 'internal' or 'public' if you want to share it with others
  - **do not* click the 'Initialize repository with README' button
- Click 'Create Project'
  - that's all you need to do in the browser, you don't need to follow the instructions you see on-screen next, instead do what it says below.

18 19
- Log into your virtual machine, or, if you're using your laptop, open a terminal window
- Do the **git config** steps, this stops git from prompting you if you haven't set these fields before. You only need to do it once per machine:
20 21 22 23 24 25 26 27 28 29 30 31 32
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR_USERNAME@ebi.ac.uk"

- Create an empty directory, go into it, and create an empty git repository there:

mkdir ~/gitlab-test
cd ~/gitlab-test
git init

- Add the code to your repository and commit it:
34 35 36

tar xvf ~/tsi-ccdoc/tsi-cc/ResOps/scripts/gitlab/tiny-test.tar
git remote add origin https://gitlab.ebi.ac.uk/YOUR_GITLAB_USERNAME/YOUR_PROJECT_NAME.git
38 39
git add .
git commit -m "Initial commit"
40 41 42 43 44 45

- Tell git to cache your password for one hour. This saves you typing it in all the time whenever you make a push to the server. This is only needed when you use the **https** URL, with the SSH URL you can use an ssh-agent to cache the connection information instead. However, the SSH URL isn't accessible outside the EBI network, so we use the https URL for portability here:

git config --global credential.helper "cache --timeout=3600"
46 47 48 49 50 51 52 53 54
git push -u origin master

Then go to the **CI/CD** -> **Pipelines** tab and watch the progress of your pipeline. Unfortunately it will fail!

### Fix the build and try again ###

The build fails because the code which is uploaded points to my personal project, which only I have access to.

To fix this, edit the **.gitlab-ci.yml** file, change the **APPLICATION** name to the name of your project, and the **REGISTRY_USER** to your gitlab username. Save the file, commit it to git, and push it to the server again. This time, you only need a ```git push```, with no extra arguments.
56 57

Go to the **CI/CD** -> **Pipelines** tab again, this time it should succeed.
Tony Wildish's avatar
Tony Wildish committed
58 59 60

### Conclusion ###

61 62
You now know how to create a project in gitlab, how to upload code to it from an existing area on your computer, and how to configure the basic features of the CI/CD pipeline to refer to this project correctly.

Tony Wildish's avatar
Tony Wildish committed
### Best Practices ###
64 65

Keep your projects small, it's better to have many small projects than a few large ones with everything bundled in together. It keeps the CI/CD pipeline cleaner and faster, as well as being good coding hygene in general.