This repository contains scripts used in CICD Pipelines for projects that still depend on an upstream Subversion repository but that use a local gitlab instance so they can leverage a better merge request and quality flow.
Pre-Requisites:
- A Jenkins server
- A Gitlab server
- (optional) A Subversion server (for the Sync part)
- (optionally) A configured SonarQube Jenkins plugin (2)
Install steps:
- Create a CICD pipeline job that points to the Jenkinsfiles/cicd.Jenkinsfile
- Create a GitSvnSync pipeline job that uses the Jenkinsfiles/synPipeline.Jenkinsfile
(1) There's a 'runSonar' variable that can be set to false to disable the use of Sonar
To run a demo with a containerized CI/CD suite, follow the instructions below. This includes instances of Jenkins, Gitlab, Sonar + db, Svn and Portainer.
Requirements:
- Docker
- At least 4gb of RAM available to Docker
- docker-compose or any other container orchestration tool
-
Create custom external network (necessary on Docker for Windows):
docker network create external_network
-
Run
docker-compose -p cicd up -d
-
Make sure all applications are up and running (gitlab takes several minutes). You can check on the status by opening the Portainer UI, by default hosted at http://localhost:9010
-
Once gitlab is up and running, go to http://localhost
- create a password for the root user,
- then log in with username root and the password you just created
- Create / Copy the private API token from Profile Settings -> Account and save for later
- Go to admin > settings > network > outbound requests, and check the 'Allow requests to the local network from hooks and services' (admin/application_settings/network)
- Create group 'demo', click on create project and from the top menu, click 'Import project', and import this project from Github (name it git-svn-pipeline)
- Create an empty project 'demo',
- In settings/repository create a deploy key with write access. (you'll need to create an ssh key, and paste the public key in the key field)
-
Go to Sonar, create an admin user and in the user settings, create a token
-
Go to Jenkins (http://localhost:8080),
- In Credentials:
- Create username/password credentials for svn with id 'svn' and user/pw tester/tester (this is defined in the Docker/svn/Dockerfile)
- Create username/password credentials for gitlab with id 'gitlab'
- Create SSH Username with private key credentials for the gitlab deploy key with id 'jenkins-deploy-key' and enter the private ssh key that matches with the public key you created for gitlab.
- In Jenkins System Settings:
- Configure SonarQube server: name 'SonarQube', Server Url 'http://sonar.intra:9000' and use the token you created in Sonar
- Configure a Gitlab connection, name it 'Gitlab', host 'http://gitlab.intra', and use the token previously created in Gitlab
- Pipeline Model definition: label 'docker.local', registry url 'http://gitlab-registry.intra' and add credentials to access gitlab
- Cloud > Docker: name 'docker.local', Docker Host URI to tcp://docker.for.win.localhost:2375
- In Global Tool Configuration:
- Configure JDK installation for Java 9 >
- Configure Maven installation and give it the nam 'maven3'
- Create a new 'freestyle' job with a maven build step, it doesn't have to point to any real maven project, but this job just needs to run once so Jenkins will download the JDK and maven you have just configured
- In Credentials:
- Create a new pipeline job (New Item > name (important!): 'pipeline-demo' and select 'pipeline' )
- Scroll down to Build Triggers, check the 'Build when a change is pushed to Gitlab' and 'opened merge requests'
- Scroll further down to the pipeline settings:
- Definition: Pipeline script from SCM
- SCM: Git
- Repositories > Repository Url: http://gitlab.intra/demo/git-svn-pipeline.git . Use git credentials you've set up earlier.
- Branches to build '*/master'
- Script Path: 'Jenkinsfiles/cicd.Jenkinsfile'
- Save
- You can try running the job, it should result in a failure as the job is getting configured from the pipeline script.
- Create a second pipeline job (name is not important this time)
- Don't set a build trigger for this job, but disallow concurrent builds
- Scroll down to pipeline settings:
- Definition: Pipeline script from SCM
- SCM: Git
- Repositories > Repository Url: http://gitlab.intra/demo/git-svn-pipeline.git . Use git credentials you've set up earlier.
- Branches to build '*/master'
- Script Path: 'Jenkinsfiles/syncPipeline.Jenkinsfile'
- Save
- Run the job 2 times (first run will fail due to parameters setup) - If everything was setup correctly, you should now see the svn repository being synced to the 'demo' git repository, and the cicd pipeline being triggered by the sync pipeline.