Commit 3f37bd0f authored by funnicus's avatar funnicus
Browse files

copied

parent 5638b565
Pipeline #45129 failed with stages
in 21 seconds
# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml
image: openjdk:latest
# This is a sample GitLab CI/CD configuration file that should run without any modifications.
# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
# it uses echo commands to simulate the pipeline execution.
#
# A pipeline is composed of independent jobs that run scripts, grouped into stages.
# Stages run in sequential order, but jobs within stages run in parallel.
#
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages
build:
stage: build
script:
- javac SiteGen.java
stages: # List of stages for jobs, and their order of execution
- build
- test
- deploy
test:
stage: test
script:
- javac -cp "./junit-platform-console-standalone-1.8.1.jar" SiteGenTest.java SiteGen.java
- java -jar junit-platform-console-standalone-1.8.1.jar -cp "." -c SiteGenTest
build-job: # This job runs in the build stage, which runs first.
stage: build
script:
- echo "Compiling the code..."
- echo "Compile complete."
unit-test-job: # This job runs in the test stage.
stage: test # It only starts when the job in the build stage completes successfully.
script:
- echo "Running unit tests... This will take about 60 seconds."
- sleep 60
- echo "Code coverage is 90%"
lint-test-job: # This job also runs in the test stage.
stage: test # It can run at the same time as unit-test-job (in parallel).
script:
- echo "Linting code... This will take about 10 seconds."
- sleep 10
- echo "No lint issues found."
deploy-job: # This job runs in the deploy stage.
stage: deploy # It only runs when *both* jobs in the test stage complete successfully.
script:
- echo "Deploying application..."
- echo "Application successfully deployed."
pages:
stage: deploy
script:
- javac SiteGen.java
- java SiteGen
artifacts:
paths:
- public
only:
- main
# DEVOPS demonstration
Build your own CI/CD pipeline to the Gitlab environment through following steps:
- Create new project to either UTU gitlab https://gitlab.utu.fi/ or Gitlab.com ​​https://gitlab.com/users/sign_in if you don’t have an UTU account
- Use the project template as a basis for your project
- The CI/CD pipeline should fail at the testing phase; read the console logs for all the phases and see what goes wrong
- Create new branch to investigate the situation; verify that the pipeline still fails
- Fix the situation by modifying the Java source code file based on the unit testing report found from the CI/CD console log
- When the testing phase goes green, merge the branch to the main branch
- The resulting web page generated by the Java application should now be deployed to the Gitlab Pages; Access the web pages via Gitlab setting and give public access to the resulting web site
- Read through the .gitlab-ci.yml file and try to understand what each line does
- Prepare to demonstrate you CI/CD pipeline and explain how it works
Note: Each step can be done using the Gitlab online tools and editors
import java.nio.file.*;
import java.util.*;
import java.util.stream.*;
class SiteGen {
static String siteTitle = "My favorite movies";
static List<String> movieList = List.of(
"Star Wars",
"Star Trek",
"Battlestar Galactica"
);
static String htmlString =
"<html>" +
"<head><title>" + siteTitle + "</title></head>" +
"<body>" +
"<h1>" + siteTitle + "</h1>" +
"<ul>" + movieList.stream().map(i -> "<li>"+ i + "</li>").collect(Collectors.joining()) + "</ul>" +
"</body>" +
"<html>";
public static void main(String args[]) throws Exception {
Files.createDirectory(Paths.get("public/"));
Files.write(Paths.get("public/index.html"), htmlString.getBytes());
}
}
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class SiteGenTest {
@Test
public void testHtmlString() {
String correctHtml = "<html><head><title>My favorite movies</title></head><body><h1>My favorite movies</h1><ul><li>Star Wars</li><li>Star Trek</li><li>Battlestar Galactica</li></ul></body></html>";
Assertions.assertEquals(correctHtml, SiteGen.htmlString);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment