Followers

GitLab- CICD assignment

  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

COMMENTS

BLOGGER: 5
  1. stages:
    - 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

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. 1. Create and Clone the Gitlab Private Repo (mavenRepo)
    - 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

    ReplyDelete
  4. pong

    mvn 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

    ReplyDelete

Name

Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,Jira,1,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SonarQube,3,Splunk,2,vagrant kubernetes,1,YAML Basics,1,
ltr
item
DevOpsWorld: GitLab- CICD assignment
GitLab- CICD assignment
DevOpsWorld
https://www.devopsworld.co.in/2022/02/gitlab-cicd-assignment.html
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/2022/02/gitlab-cicd-assignment.html
true
5997357714110665304
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content