I have a spring-boot maven application I've been running locally as:
mvn spring-boot:run
I want to be able to run this in GitLab runner so that when I push the code to master, it automatically copies the latest up there and runs the application.
My GitLab runner is configured in shell mode right now, and I have inside of the .gitlab-ci.yml file a deploy task that runs just that:
mvn spring-boot:run
The issue I am running into is after the application starts, I can see that it is running... but it never shows as success or completed. It just hangs there (because the terminal is still running when you execute that command?)
Question is, is there an alternate set of commands I should be running to get my spring-boot application to update and run each time I push to master? What is it i should be putting into my gitlab-ci.yml (or other files). Note that I am not using docker or kubernetes... just shell.
Sample gitlab CI:
run-deploy:
stage: deploy
script:
- mvn $MAVEN_CLI_OPTS spring-boot:run
Trying nohup with that also fails.
- nohup mvn $MAVEN_CLI_OPTS spring-boot:run &
I believe you can use the run stage for this. It would look something like
run:
stage: run
script:
- mvn $MAVEN_CLI_OPTS spring-boot:run
You can see an example of this here.
Make sure you also define the stages to include run as the docs state
If no stages are defined in .gitlab-ci.yml, then the build, test and deploy are allowed to be used as job’s stage by default. (see stages)
Is the sample file you provided above your entire configuration file or only a snippet of it? If so, I can adjust my answer to fit your needs. Thanks!
I'm sorry this is so late. I've recently just had the same problem. Gitlab runner blocks on child processes, and any process in the child tree. This makes the disown command impossible since you can't get to it. Forking, and nohup also don't work.
The only solution I could figure out was using the at command https://linux.die.net/man/1/at
Basically I put my command in a script then did:
at now < my_blocking_command_script.sh
That successfully complete the runner and kicked off my program in the background.
Related
I checked the other posts but they are not what my issue represents.
I'm doing the Linuxacademy "Certified Jenkins Engineer" course and at the "Functional Testing" lesson, we add a docker agent with some steps in the Jenkinsfile but I am confused about the syntax used vs the syntax described in the official Jenkins Pipeline documentation Using Docker with Pipeline.
What the Jenkins tries to achieve is to run a test on a.jar file on a Jenkins node with CentOS but the test needs to be run on a Debian OS, in order to do that on the CentOS node, the Jenkinsfile has a stage with a Docker agent and a commmand that pulls the openjdk image from Dockerhub and run some command in it.
This is the syntax from the Lesson Repo:
stage("Test on Debian") {
agent {
docker 'openjdk:8u121-jre'
}
steps {
sh "wget http://brandon4231.mylabserver.com/rectangles/all/rectangle_${env.BUILD_NUMBER}.jar"
sh "java -jar rectangle_${env.BUILD_NUMBER}.jar 3 4"
Note that I simplified the file to match the work in progress, this one is the final version, but the focus is on the agent line.
My first question is that the Jenkins documentation syntax is different from the one used here but in the lesson video it runs with no issues, the correct syntax should be agent {
docker { image 'openjdk:8u121-jre' }
}
My second question is, wheter I use one or the other syntax, and also I used the openjdk:7u181-jre because the one from the lesson is not longer available, I get this error in the console log output:
If go to the node terminal and manually run
docker run openjdk:7u181-jre
it works fine, I run it as not sudo user.
Also I don't understand what the docker command does in the Jenkinsfile: Does it run the container after pulling it or just pull the container?
Any idea about what's going on?
Thanks.
1) Please install docker in the Jenkins server.
2) Please change the user-mode of Jenkins and docker same by running below command and restart both Jenkins and docker and now u will be able to access.
sudo usermod -aG docker jenkins-server-user-name
sudo systemctl restart docker
sudo systemctl restart jenkins
To install Jenkins: https://www.digitalocean.com/community/tutorials/how-to-install-jenkins-on-ubuntu-16-04
To install Docker: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04
Note: Verified on ubuntu server
I am quite new to Jenkins and Docker so I am stuck with trying to make them work together. What I want is to do next steps:
Build my project war-file on Jenkins (Done)
Update Docker image and container. In my case I want to stop running container (Tomcat on it), change war-file to the newest and then run it again.
I've already deploy my application on Docker, but this app is not updated by Jenkins.
I found some plugins, like docker-build-step or docker-plugin, however there are not enough information and tutorials about it and I find it really annoying spending hours and making random suggestions.
I would appetiate any useful tutorial as more spesific as possible.
Perhaps you don't need any of these plugins. You can implement it using command api of docker.
You need to install docker on the jenkins host machine.
Then in your Jenkins build config mvn plugin(or execute shell) to build target:
clean package assembly:assembly -Dmaven.test.skip=true
execute shell something like:
docker build --net=host -t reg.docker.xxx.com/xxx/xxx:latest ./
docker login --username=xxx --password=xxx reg.docker.xxx.com
docker push reg.docker.xxx.com/xxx/xxx:latest
execute shell bellow:
docker -H tcp://swarm.xxx.com:<port> --tlsverify --tlscacert=./ca.pem --tlscert=./cert.pem --tlskey=./key.pem run -v /home/admin/rc.local:/etc/rc.local:ro reg.docker.xxx.com/xxx/xxx:latest
------Edit-------
use docker upgrade if updating existing containers.
I inherited Android Java-code in my company, without Gradle-files etc, and I want to be able to compile this on my dev-server (I program from a ChromeOS machine, hence a CLI SSH connection to a server where I do dev stuff). Now I found some Docker images like this one (which doesn't even have a working command line example) but I haven't managed to create an APK yet. What am I missing and how would you do this?
You have three steps to do:
Migrate your project to gradle.
It isn't too difficult since there are plenty of gradle project out there and you can try to follow them or just read "Migrating to Gradle" article.
Build project with gradle on local machine.
If you migrated properly you can build your project in terminal like:
./gradlew assembleDebug
but it might be also assembleDevDebug or assembleProdRelease which depends on your buildType and flavor in gradle. Check which assembles are available by running:
./gradlew tasks
Build project using Docker.
Based on image you linked:
docker run -t -i ksoichiro/android -v /path/to/project:/workspace -w workspace /bin/sh -c "./gradlew assembleDebug"
I am working on a project with Maven and Surefire plugin v. 2.11.
To run single tests I am using -Dtest=TestClass#testMethod and -DforkMode=never (without DforkMode=never I can't run tests because of lack of space for object heap). I got used to it and it was working for me fine.
So I am running:
mvn -Dtest=TestClass#testMethod test -DforkMode=never
and test is run fine.
But when I am running
mvn -Dtest=TestClass#testMethod -Dmaven.surefire.debug test -DforkMode=never
it just skips debug "waiting" part and the test is being executed (I am unable to connect using IDE).
mvn -Dmaven.surefire.debug test works for me fine with other project (where I don't need to care about fork mode).
Any ideas why the combination of forkMode=never and -Dmaven.surefire.debug doesn't work as expected?
The property maven.surefire.debug is setting the debugForkedProcess parameter of the surefire plugin.
The documentation for this parameter reads as follows:
Attach a debugger to the forked JVM. If set to "true", the process will suspend and wait for a debugger to attach on port 5005. If set to some other string, that string will be appended to the argLine, allowing you to configure arbitrary debuggability options (without overwriting the other options specified through the argLine parameter).
So it will only debug forked JVMs, which explains why it doesn't work when the tests aren't being forked. It isn't able to setup the debugging of a non-forked JVM process that is already running.
Use mvnDebug
What you can do instead is use mvnDebug, which allows you to debug the maven process itself - and as your tests are not being forked those as well.
i.e. instead of mvn -Dtest=TestClass#testMethod test -DforkMode=never you would execute mvnDebug -Dtest=TestClass#testMethod test -DforkMode=never. By default it will listen on port 8000 when it starts maven.
I wrote a little script to compile the test version of a .jar and put it out on my test server.
cd /home/myusername/workspace/td-daily-budget
mvn -P test clean compile package
scp /home/myusername/workspace/td-daily-budget/target/td-daily-budget-1.0.jar myusername#666.666.666.666:/home/myusername/bin/td-daily-budget.jar
When I run it I get a jar file whose config.properties contains things like
db.connect.string=${db.connect.string}
but when I run mvn -P test clean compile package all by itself in the terminal window I get a jar file put together with the test profile, e.g. config.properties contains db.connect.string=[what I expect it to be for the dev profile]. Why does the same command ignore the profile when run inside a script?
Thanks in advance!
[edit/addendum]
Tried changing the script line to
/bin/bash mvn -P env-test clean package
(it's bash, not Windows, so there's no call command, but using bash to call another script seems to make sense to me) but just got
*Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
*
I think calling it as an external process mucks up Maven's understanding of where it's supposed to be executing.
[2nd edit/addendum]
Removed the redundant compile from the command.
It now appears that this is actually an intermittent problem. The filtering almost always fails when mvn -P [pretty much ANY profile] clean package runs from inside the bash script, but if I run it standalone from the command line repeatedly it will work eight or nine times and then fail several times in a row. I cannot find any pattern to this at all.
As soon as I discovered this I thought I knew the culprit: The m2e plugin for Eclipse was "helping" me in the background every time it saw files changing. So I excitedly shutdown Eclipse thinking the problem would vanish instantly, ran mvn -P env-test clean compile package several times in a row--it worked the first few times and then failed. /headdesk
[edit/addendum]
Removed the space between the -P and the profile name. Still no luck.
I think you need to run the mvn in your batch with "call" command, so sth like:
call mvn -P test clean compile package
The reason is, that mvn is a batch file itself and thus needs to be invoked with "call".
Please give it a try!
Bluddy
Are you allowed to have a profile with the same name as a phase? Try renaming your "test" profile to "env-test" and use:
mvn -P env-test clean package
EDIT:
If you believe it has to do with calling it from a script, try adding a bash declaration at the top:
#!/bin/bash
cd /home/myusername/workspace/td-daily-budget
mvn -P env-test clean package
scp /home/myusername/workspace/td-daily-budget/target/td-daily-budget-1.0.jar myusername#666.666.666.666:/home/myusername/bin/td-daily-budget.jar
Credit Bluddymarri for suggesting the batch script equivalent.