I created a .gitlab-ci.yml file and tried to deploy my maven repository on gitlab to heroku. Unfortunately I don't understand how to do this without the heroku-cli (which I could not install on gitlab).
The build process and test process is not failing but the deployment process is due to my lack of information about how it exactly works.
The yml file I created looks like this:
before_script:
- apk update && apk add git
- apk update && apk add openjdk8
- apk update && apk add maven
- git --version
build:
stage: build
script:
- mvn compile
test:
stage: test
script:
- mvn test
deploy:
stage: deploy
script:
- heroku git:remote -a NAME_OF_MY_HEROKUAPP
- git push heroku master
only:
- master
Related
In my gitlab-ci.yml configuration I have the following snippet:
before_script:
- java -jar /home/gitlab-runner/tools/ciVersioner-1.0.jar $MAJOR $MINOR $CI_COMMIT_SHORT_SHA
script:
- mvn --projects employees --also-make clean package -DskipTests
after_script:
- echo $HOSTNAME $WHOAMI
artifacts:
paths:
- employees/target/*.jar
expire_in: 30 days
It does not work but for a different reason (since java versions are incompatible).
Here's the output:
The solution was to install a newer java 11.
I did so and changed the configuration correspondingly:
before_script:
- /opt/java11/jdk-11/bin/java -jar /home/gitlab-runner/tools/ciVersioner-1.0.jar $MAJOR $MINOR $CI_COMMIT_SHORT_SHA
script:
- mvn --projects employees --also-make clean package -DskipTests
after_script:
- echo $HOSTNAME $WHOAMI
artifacts:
paths:
- employees/target/*.jar
expire_in: 30 days
However, with this configuration nothing works at all:
But if I execute this command in VM environment directly, it works as expected.
Is there a limitation on using full qualified path in the yml file or maybe it has to do with something else?
Before you updated java the job fail at the java command, so it didn't try to execute mvn.
However, when the first problem is solved, you get a new issue and now with mvn command.
I guess the runner cannot recognize mvn because maven is not installed.
You could try adding the following to the before_script section:
- apt-get update && apt-get install maven
This is will depend on the linux distribution, use yum instead if the runner is on redhat or centos
I'm having a problem with my .war file deployment through CodePipeline (using CodeBuild) to my Elastic Beanstalk environment. After a successful pipeline deployment, it throws a 404 error (see picture).
However, when I upload the .war file from my project code directly into my Elastic Beanstalk environment, it works just fine.
Ideally, I want to just be able to run the CodePipeline to update the versioning.
My CodeBuild (buildspec) -
version: 0.2
phases:
install:
runtime-versions:
java: corretto11
build:
commands:
- ls -la
- cd prod/
- mvn clean
- mvn install
# post_build:
# commands:
artifacts:
files:
- backend/target/backend-0.0.1-SNAPSHOT.war
# name: artifact
base-directory: prod/
404 Error -
I've tried this as well and it still gives me a 404 error
version: 0.2
phases:
install:
runtime-versions:
java: corretto11
build:
commands:
- ls -la
- cd prod/
- mvn clean
- mvn install
post_build:
commands:
- mv backend/target/backend-0.0.1-SNAPSHOT.war ROOT.war
artifacts:
files:
- ROOT.war
AWS Elastic Beanstalk expects to find and run a ROOT.war at root directory.
ROOT.war runs at myapp.elasticbeanstalk.com. In a single WAR source
bundle, the application always runs at the root path.
(Source)
You have two options to resolve this
Make sure that your artifact is named ROOT.war and is found at root level (in contrary to backend/target/backend-0.0.1-SNAPSHOT.war)
Use the post_build phase in your CodePipeline to rename and move the file adequately (the easier option).
Option 2 approach:
post_build:
commands:
- mv backend/target/backend-0.0.1-SNAPSHOT.war ROOT.war
I've been trying to set up GitLab-CI to build Maven Java projects in Raspbian, but whenever It tries to run the build script it fails because it can't find Maven. I used this guide to install the runner.
Build trace:
Running with gitlab-ci-multi-runner 1.10.4 (b32125f)
WARNING: image is not supported by selected executor and shell
Using Shell executor...
Running on raspberrypi...
Cloning repository...
Cloning into '/home/gitlab-runner/builds/f09314a8/0/RBian/TestProject'...
Checking out 54d2e140 as master...
Skipping Git submodules setup
$ mvn clean package
bash: line 22: mvn: command not found
ERROR: Build failed: exit status 1
.gitlab-ci.yml
image: maven:3-jdk-8
build:
script: "mvn clean package"
artifacts:
name: "TestProject"
paths:
- "target/*.jar"
Does anyone know what causes this?
EDIT: Modifying /etc/default to add $MAVEN_HOME/bin to $PATH did the trick.
Try adding MAVEN_HOME path into config.toml environment field.
environment = ["MAVEN_HOME=/path/to/maven"]
I have a java project that I am hosting on GitHub. I also have a Docker file that creates an image based off of the generated war files after a build (using Maven).
What I want is for a new Docker image to be generated every time I push new code to the repo. What I am getting confused with is how will Docker build the source and add the generated .war files to the base Tomcat Docker file? Or am I thinking about this wrong?
Alternatively is there a way for Travis CI to generate the war and then push it to a docker image?
So to fix this, I had Travis CI pull data from the repo and after the build have the docker file pull the artifacts from the target directory and push the built docker image to docker hub.
.travis.yml
language: java
sudo: true
services:
- docker
cache:
directories:
- $HOME/.m2
jdk:
- oraclejdk8
os:
- linux
branches:
only:
- master
after_success:
- docker login -e="$DOCKER_EMAIL" -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
- docker build -t blah/blah .
- docker push blah/blah
Dockerfile:
# Pull base image
From tomcat:8-jre8
# Maintainer
MAINTAINER "Joel"
# Copy to images tomcat path
COPY target/blah*.war /usr/local/tomcat/webapps/sacred-text-api.war
I have a JHipster project I want to build through Travis CI and then deploy to Heroku. However, even if Travis CI passes the build, it commits the whole code to Heroku and then Heroku tries to build the whole project again, defeating the purpose of having Travis CI in the middle.
Is there a way to build my project with Travis CI and then just deploy the build WAR to Heroku?
Given the fact that JHipster uses Spring Boot, I would only need the WAR to run the application.
Here is my .travis.yml files:
language:
- java
jdk:
- oraclejdk8
sudo: false
env:
- MAVEN_CUSTOM_OPTS="-Pprod,heroku -DskipTests"
before_install:
- npm install -g npm
- rm -fr /home/travis/.npm/
- npm cache clean -g
- npm install grunt-cli -g
- npm install
install:
- mvn package -Pprod -DskipTests
script: true
notifications:
webhooks:
on_success: change
on_failure: always
on_start: false
deploy:
provider: heroku
api_key:
secure: [key]
skip_cleanup: true
Also, if there is another way to deploy a Spring Boot application through this process, it would be great.
Thank you.
You can install the heroku-deploy plugin on Travis CI and deploy the same way you deploy to Heroku locally.
In fact, this is what the heroku-deploy plugin does to test itself, so you can use it as an example. The setup script downloads the Ubuntu installer for the toolbelt from: https://toolbelt.heroku.com/install-ubuntu.sh
Then you'll only need to install the plugin with this command in your setup script:
heroku plugins:install https://github.com/heroku/heroku-deploy
And set your API key as a secure variable in the .travis.yml