devstream
devstream copied to clipboard
:four_leaf_clover: `Proposal`: New plugin gitlab-pipeline
What Would You Like to Add? Why Is This Needed?
The current gitlab plugin only supports golang, I would like to add a plugin for the java language. This plugin is for Gitlab-Java's pipeline workflow.
Design
exmaple .gitlab-ci.yml
image: docker:stable
stages:
- package
- docker_build
- k8s_deploy
mvn_package_job:
image: maven:3.6.2-jdk-14
stage: package
tags:
- java-demo
script:
- mvn clean package -B
artifacts:
paths:
- target/*.jar
docker_build_job:
image: docker:latest
stage: docker_build
tags:
- java-demo
script:
- docker login -u hxcdockerhub -p GITLAB_TOKEN
- docker build -t hxcdockerhub/java-demo:$CI_PIPELINE_ID .
- docker push hxcdockerhub/java-demo:$CI_PIPELINE_ID
k8s_deploy_job:
image:
name: bitnami/kubectl:latest
entrypoint: [""]
stage: k8s_deploy
tags:
- java-demo
script:
- kubectl config get-contexts
- kubectl config use-context hxcGit/java-demo:hxc
- cd manifests
- sed -i "s/IMAGE_TAG/$CI_PIPELINE_ID/g" deployment.yaml
- cat deployment.yaml
- kubectl apply -f deployment.yaml
Option struct
// Options is the struct for configurations of the gitlabci-java plugin.
type Options struct {
PathWithNamespace string `validate:"required"`
Branch string `validate:"required"`
BaseURL string `validate:"omitempty,url"`
Package *Package `validate:"required"`
Build *Build `validate:"required"`
Deploy *Deploy `validate:"required"`
}
type BaseOption struct {
Enable bool `validate:"required"`
Image string
Tags string
}
type Package struct {
BaseOption `validate:"required"`
ScriptCommand []string
}
type Build struct {
BaseOption `validate:"required"`
UserName string
ImageName string
ScriptCommand []string
}
type Deploy struct {
BaseOption `validate:"required"`
ScriptCommand []template.HTML
K8sAgentName string
}