Assignment Maven Project Gitlab CICD Pipeline 1. Create and Clone the Gitlab Private Repo (mavenRepo) 2. Setup an Access Token for your ac...
Assignment
Maven Project Gitlab CICD Pipeline
1. Create and Clone the Gitlab Private Repo (mavenRepo)
2. Setup an Access Token for your account for pulling and pushing the code into mavenRepo.
3. Generate a maven archetype and push those changes to the maven repo
4. Setup local git lab runner with some tags(localrunner,localshell)
5. Push the code into mavenRepo.
6. Create .gitlab-ci.yml file for your ci cd pipeline
7. Create a build stage where a jar file into a target folder of your maven local project
8. Create a test stage you need to check that jar file exist in the target folder.
9. Create a parallel test case that is a dummy stage.(echo "Testing is done")
10 Deploy your application by running java -cp command
The solution for CICD pipeline is below
stages:
- build
- test
- deploy
build:
stage: build
tags:
- localrunner
- localshell
script:
- cd /home/vagrant/mvnrepo
- sudo mvn clean package
test:
stage: test
tags:
- localrunner
- localshell
script:
- sudo ls /home/vagrant/mvnrepo/target/*.jar
newtest:
stage: test
tags:
- localrunner
- localshell
script:
- sudo touch /home/vagrant/mvnrepo/passtest
deploy:
stage: deploy
tags:
- localrunner
- localshell
script:
- cd /home/vagrant/mvnrepo
- sudo java -cp target/myproj-1.0-SNAPSHOT.jar com.raman.App
stages:
ReplyDelete- build
- test
- deploy
build:
image: maven
stage: build
tags:
- localrunner
- localshell
script:
- cd mavenproj
- mvn clean package
artifacts:
paths:
- mavenproj/target
# expire_in: 1 week
test:
image: maven
stage: test
tags:
- localrunner
- localshell
script:
- ls mavenproj/target/
artifacts:
paths:
- mavenproj/target
# expire_in: 1 week
parallel test:
stage: test
tags:
- localshell
- localrunner
script:
- echo "Testing complete"
artifacts:
paths:
- mavenproj/target
# expire_in: 1 week
deploy:
image: maven
stage: deploy
tags:
- localshell
- localrunner
script:
- java -cp mavenproj/target/mavenproj-1.0-SNAPSHOT.jar com.naveen.App
Execllent
DeleteThis comment has been removed by the author.
ReplyDelete1. Create and Clone the Gitlab Private Repo (mavenRepo)
ReplyDelete- Created new repo on Gitlab (mavenRepo)
- Cloned repository to local system via ssh using: git clone git@gitlab.com:jeromechong02/mavenrepo.git
- > ls to check if folder had been cloned successfully (yes)
2. Setup an Access Token for your account for pulling and pushing the code into mavenRepo.
- On GitLab go to Edit Profile>Access Tokens and add a personal access token (select all scopes)
- Save token (xxxx....)
3. Generate a maven archetype and push those changes to the maven repo
- In CLI enter: mvn archetype:generate fill in properties
- Project created from Archetype in dir: /home/vagrant/mvnRepo
- To push changes to the maven repo:
- > mvn compile
- > cd mvnRepo/
- > ls
- > cp -r * /home/vagrant/mavenrepo/
- > cd ..
- > ls mavenrepo/
- > git status
- > cd mavenrepo/
- > git status
- > git add -A
- > git commit -m "mavenRepo project is added"
- > git push origin main
- Checked repo on GitLab to confirm if files are synced (yes)
4. Setup local git lab runner with some tags(localrunner,localshell)
- On GitLab go to Settings>CD/CD>Runners and view specific runner details.
- In CLI enter: sudo gitlab-runner register
- Details: https://gitlab.com/; 6n4Wez_wb2Ue-yP_spfe; mavenRepo registration token; localrunner, localshell
- Check runner under “Available specific runners”
5. Push the code into mavenRepo.
- In CLI enter: ssh-keygen
- Key generated: SHA256:xxxxxx....
- touch test.js
6. Create .gitlab-ci.yml file for your ci cd pipeline
- On GitLab, Repository>Files> + New File (select template .gitlab-ci.yml)
- Commit changes and check (passed)
[[7. Create a build stage where a jar file into a target folder of your maven local project
8. Create a test stage you need to check that jar file exist in the target folder.
9. Create a parallel test case that is a dummy stage.(echo "Testing is done")
10 Deploy your application by running java -cp command]]
Put this code in the .yml file:
stages:
- build
- test
- deploy
build:
stage: build
tags:
- localrunner
- localshell
script:
- cd /home/vagrant/mavenrepo
- sudo mvn clean package
test:
stage: test
tags:
- localrunner
- localshell
script:
- sudo ls /home/vagrant/mavenrepo/target/*.jar
newtest:
stage: test
tags:
- localrunner
- localshell
script:
- sudo touch /home/vagrant/mavenrepo/passtest
deploy:
stage: deploy
tags:
- localrunner
- localshell
script:
- cd /home/vagrant/mavenrepo
- sudo java -cp target/mvnRepo-1.0-SNAPSHOT.jar com.jerome.App
pong
ReplyDeletemvn archetype:generate
734 ls
735 cp myproj/* mavenrepo/
736 cp -R myproj/* mavenrepo/
737 cd mavenrepo
738 ls
739 git status
740 git add .
741 git commit -m "maven project has been added"
742 git push origin main
743 cd ..
744 mvn clean
745 ls
746 mvn clean package
747 sudo mvn clean package
748 curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash
749 sudo apt install docker.io -y
750 sudo apt-get install gitlab-runner
751 gitlab-runner -v
752 sudo gitlab-runner register
753 mvn clean package
754 cd mavenrepo
755 mvn clean package
756 vi /etc/sudoers
757 history
stages:
- build
- test
- deploy
build:
stage: build
tags:
- localrunner
- localshell
script:
- cd /home/vagrant/mavenrepo
- sudo mvn clean package
test:
stage: test
tags:
- localrunner
- localshell
script:
- sudo ls /home/vagrant/mavenrepo/target/*.jar
newtest:
stage: test
tags:
- localrunner
- localshell
script:
- sudo touch /home/vagrant/mavenrepo/passtest
deploy:
stage: deploy
tags:
- localrunner
- localshell
script:
- cd /home/vagrant/mavenrepo
- sudo java -cp target/myproj-1.0-SNAPSHOT.jar com.pong.App