My goal is to deploy 1 spring-config-server application AND 1 spring-boot-client application to the same Linux server machine.
spring-boot-client application port is 8081
spring-config-server application port is 8888
In Jenkins I created 2 jobs. First job is to build and deploy the spring-config-server application and start the jar. Second job is is to build and deploy the spring-boot-client application and start the jar.
I was able to build and deploy the spring-config-server application to the Linux machine. I can see it running at localhost:8888
Problem : Build task/job for spring-boot-client application in Jenkins is failing because when maven clean install is run, I believe that it tries to locate presence of a config server running at localhost:8888. I don't know if it's because of actuator dependency I added.
In Jenkins build console, this is what I get
Caused by: org.springframework.web.client.ResourceAccessException: I/O
error on GET request for "http://localhost:8888/application/dev":
Connection refused (Connection refused); nested exception is
java.net.ConnectException: Connection refused (Connection refused) at
org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:785)
at
org.springframework.web.client.RestTemplate.execute(RestTemplate.java:711)
at
org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:602)
at
org.springframework.cloud.config.client.ConfigServerConfigDataLoader.getRemoteEnvironment(ConfigServerConfigDataLoader.java:303)
at
org.springframework.cloud.config.client.ConfigServerConfigDataLoader.doLoad(ConfigServerConfigDataLoader.java:118)
... 94 common frames omitted Caused by: java.net.ConnectException:
Connection refused (Connection refused)
In the spring-boot-client app's application.properties, the only setting I have are these :
# ANT_PATH_MATCHER is added to avoid NULL error in SwaggerConfig
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
server.port=8081
# Spring Config Server URL of Config Server Microservice :
spring.config.import=configserver:http://localhost:8888
# Environment configuration which you want to load :
spring.profiles.active=dev
In spring-boot-client's jenkins build job, this is what I have :
Now, theoretically, I believe that deploying 1 config-server and 1 client-app in the same linux machine should be possible. I just don't know how to properly configure it in Jenkins.
I have this spring cloud config client in pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
<version>3.1.3</version>
</dependency>
I have a copy of the spring-config-server app and spring-boot-client app in my local machine. I just start/run both and it works.
I am a beginner in Jenkins and I do everything in UI. This is just a build task with scp and ssh commands executed in shell to deploy.
I'd appreciate any help or comment.
Thank you.
I'm using external Nexus repository for java maven project and I trying to config circleCI config. At first I need to somehow say CircleCI to look into env variables for credentials during build.
In grade driven java projects all going fine without any extra configs, but in maven it says that can't have access to nexus.
Have anybody experience with it?
It's my first time configuring CircleCI
UPD1:
For authorisation I added env variables for username, password, server url and attributes to context on CircleCI Organization Settings page
I using this ORB and there I have found the names of env variables I have to use as default names.
Created circleci config file:
version: 2.1
orbs:
nexus-platform-orb: sonatype/nexus-platform-orb#1.0.28
workflows:
main:
jobs:
- nexus-platform-orb/nexusjob:
context: MyContext
And have this error:
Caught: java.io.FileNotFoundException: /tmp/workspace (Is a directory)
java.io.FileNotFoundException: /tmp/workspace (Is a directory)
at NexusPublisher.run(NexusPublisher.groovy:59)
Exited with code exit status 1
But when I added command to create file inside and used it, I steel have the same problem.
For a which file or directory circleci is looking for?
UPD1:
I a bit updated my config file:
version: 2.1
orbs:
maven: circleci/maven#1.3.0
nexus-platform-orb: sonatype/nexus-platform-orb#1.0.28
jobs:
install-nexus:
executor: nexus-platform-orb/nexus-platform-cli
steps:
- checkout
- nexus-platform-orb/install
workflows:
main:
jobs:
- install-nexus
- nexus-platform-orb/nexusjob:
context: MyContext
workspace: tmp/workspace/
requires:
- install-nexus
As a result I have an error running this job:
/bin/sh: curl: not found
Because command nexus-platform-orb/install contains this line:
curl -L
https://groovy.jfrog.io/artifactory/libs-release-local/org/codehaus/groovy/groovy-binary/<<
parameters.groovy-version >>/groovy-binary-<< parameters.groovy-version
>>.zip -o apache-groovy-binary.zip
But adding command installing curl gives me one another error:
steps:
- checkout
- run: apk update && apk add curl curl-dev bash
- nexus-platform-orb/install
#!/bin/sh -eo pipefail
apk update && apk add curl curl-dev bash
ERROR: Unable to lock database: Permission denied
ERROR: Failed to open apk database: Permission denied
Exited with code exit status 99
And I have no idea how to fix it, because only way I found is to add RUN root to the Dockerfile. But it not works.
UPD2:
I spent more than week to understand how to fix it and posted my resolution as an answer.
Hope it will save time for someone.
The resolution of this problem is to manually say what exactly file to use for getting credentials.
This is how my config.yml file looks after all:
version: 2.1
orbs:
maven: circleci/maven#1.3.0
jobs:
build:
executor: maven/default
working_directory: ~/my-project
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "pom.xml" }}
- v1-dependencies-
- run:
name: Test
command: |
mvn -s ./settings.xml clean test
- save_cache:
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "pom.xml" }}
workflows:
main:
jobs:
- build
I do not need nexus orb anymore. I used maven orb for an executor.
Added command mvn -s ./settings.xml clean test to run tests and says in which file nexus credentials are.
settings.xml file:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>MYPROJECT</id>
<username>*****</username>
<password>*****</password>
</server>
</servers>
</settings>
And link to Nexus repository I added in pom.xml file:
<repositories>
<repository>
<id> MYPROJECT </id>
<name>*****</name>
<url>https://nexus.*****/</url>
</repository>
</repositories>
Hope this case will help someone.
My machine is using proxy to connect internet. But I get the following error when running maven build command. And it works when I disable proxy. I don't understand why proxy matters here.
[ERROR] Failed to execute goal on project flink-dist_2.11: Could not resolve dependencies for project org.apache.flink:flink-
dist_2.11:jar:1.7-SNAPSHOT: Failed to collect dependencies at
org.apache.flink:flink-shaded-hadoop2-uber:jar:1.7-SNAPSHOT:
Failed to read artifact descriptor for org.apache.flink:flink-shaded-hadoop2-uber:jar:1.7-SNAPSHOT:
Could not transfer artifact
org.apache.flink:flink-shaded-hadoop2-uber:pom:1.7-SNAPSHOT from/to apache.snapshots (https://repository.
apache.org/snapshots): Remote host closed connection during handshake: SSL peer shut down incorrectly -> [Help 1]
Have you tried the settings.xml at ${user.home}/.m2/settings.xml , more guidance here https://maven.apache.org/guides/mini/guide-proxies.html
in windows7 and above it would be c:\users\user_name\.m2
Maven is trying to connect to a remote repository in order to downlod your project dependencies in its local repository. That's a network connection and obviously, your proxy configuration makes Maven fail in the attempt.
Remote host closed connection during handshake: SSL peer shut down incorrectly :
This indicates that the server host that your are trying to achieve is down, verify first if the connection is well established and try again.
May be try this by configuring Mavan accordingly for using the proxy server:- https://dzone.com/articles/how-get-maven-working-through
I faced to the same problem at my work where we have Windows workstations and NTLM2 proxy server with authentication.
The following solution works fine for me. The benefit of this solution is that it can work with Maven, Git, IntelliJ IDE as well.
Reccomended steps you need to accomplish in order to have access via NTLM2 proxy:
First you need to download, configure and run Cntlm proxy on your pc.
Start Cntlm on your localhost. This proxy will forward all your local unauthenticated HTTP/HTTPS requests to the company proxy as a authenticated requests.
Configure Maven, Git, IntelliJ, Eclipse, etc. to use your local proxy on localhost:3128. You do not need to configure authentication here.
Details:
Download Cntlm proxy from here.
Type cntlm.exe -H -d your_domain -u your_username.
It will ask your password. Enter it and Cntlm will give you the hashes, something like this:
Password:
PassLM 4E9C185932FER43543RWEFER33R4R34C
PassNT 6E9F1254353RDR34RFSDWER3443RDC9A
PassNTLMv2 43534RFWDWE3434RWFWER434C4FA224F
Edit / check your cntlm.ini file
Username <your-domain-username>
Domain <windows-donain-name>
Auth NTLMv2
PassNTLMv2 <hash>
Proxy <proxy-host:port>
NoProxy localhost, 127.0.0.*, 10.*, 192.168.*
Listen 3128
Start Cntlm with a simple script: start-proxy.cmd
cd %CNTLM_HOME%
rem verbose mode
cntlm -v -c cntlm.ini
rem verbose with logfile
rem cntlm -v -c cntlm.ini -T %CNTLM_HOME%\nctlm.log
rem test configuration
rem cntlm -c cntlm.ini -I -M http://google.com
Stop Cntlm server: stop-proxy.cmd
taskkill /IM cntlm.exe /F
Then you can create two cmd files which change Maven configuration as per your flavour:
mvn-internet.cmd
call java8.cmd
del %MAVEN_HOME%\conf\settings.xml
copy %MAVEN_HOME%\conf\settings.xml.internet %MAVEN_HOME%\conf\settings.xml
mvn-intranet.cmd
call java8.cmd
del %MAVEN_HOME%\conf\settings.xml
copy %MAVEN_HOME%\conf\settings.xml.nexus %MAVEN_HOME%\conf\settings.xml
settings.xml.internet
<settings xmlns=...>
<localRepository>...</localRepository>
<proxies>
<proxy>
<id>my-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>localhost</host>
<port>3128</port>
<nonProxyHosts>locahost</nonProxyHosts>
</proxy>
</proxies>
</settings>
settings.xml.nexus
<settings>
<localRepository>...</localRepository>
<mirrors>
<mirror>
<id>local-lalm</id>
<name>local-lalm</name>
<url>https://nexus.xxx...</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>use-local-repo</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>LALM-global</id>
<url>https://nexus.xxx...</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>LALM-global</id>
<url>https://nexus.xxx...</url>
</pluginRepository>
</pluginRepositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</profile>
</profiles>
</settings>
Do the same with Git
git-internet.cmd
call java8.cmd
rem git config --global http.proxy username:password#localhost:3128
git config --global http.proxy localhost:3128
git-intranet.cmd
call java8.cmd
git config --global --unset http.proxy
Cunfigure IntelliJ
Set up IntelliJ to use proxy on localhost:3128
Set up Maven in IntelliJ: change Maven home directory and User settings file configs.
After that you will use the same Maven configuration within IntelliJ and command line so everythink will work on the same way from IDE and comand line.
You can use your new cmd files to change between use or not proxy server on the fly.
This configuration takes 10 mins. and after that you can forgot this proxy issue.
I am trying to run a simple Spring application through Maven.
I have followed the following guide exactly: https://spring.io/guides/gs/serving-web-content/
However, when I run: ./mvnw spring-boot:run -e -X
I get the following error:
[FATAL] Non-resolvable parent POM for org.springframework:gs-serving-web-content:0.1.0: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.5.2.RELEASE from/to central (https://repo.maven.apache.org/maven2): Connect to 192.168.208.51:3128
In a previous guide I was told to add this as the settings.xml file in the .m2 directory:
<settings>
<proxies>
<proxy>
<id>example-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>192.168.208.51</host>
<port>3128</port>
<nonProxyHosts>*.google.com|*example.com</nonProxyHosts>
</proxy>
</proxies>
</settings>
Which has the host IP address that the error is referring to.
I've pinged the IP address above and no response.
All I want to do is run the application locally as the Spring.io guide suggests is possible.
I don't fully understand the setup as of yet.
Can anyone suggest what I'm doing wrong. (I feel it is something to do with the IP address in the settings.xml file.
The IP you're using is in the private network range.
I'm attempting to run the mvn release:prepare goal and it's hanging after the push. Any idea what I could be doing wrong?
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] BUILD SUCCESSFUL
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 8 seconds
[INFO] [INFO] Finished at: Tue Jul 13 23:54:59 PDT 2010
[INFO] [INFO] Final Memory: 55M/294M
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] Checking in modified POMs...
[INFO] Executing: cmd.exe /X /C "git add -- pom.xml"
[INFO] Working directory: C:\development\taylor\my-app
[INFO] Executing: cmd.exe /X /C "git status"
[INFO] Working directory: C:\development\taylor\my-app
[INFO] Executing: cmd.exe /X /C "git commit --verbose -F C:\Users\TAYLOR~1\AppData\Local\Temp\maven-scm-1932347225.commit pom.xml"
[INFO] Working directory: C:\development\taylor\my-app
[INFO] Executing: cmd.exe /X /C "git symbolic-ref HEAD"
[INFO] Working directory: C:\development\taylor\my-app
[INFO] Executing: cmd.exe /X /C "git push git#github.com:tleese22/my-app.git master:master"
[INFO] Working directory: C:\development\taylor\my-app
>>>> hangs here <<<<
Below is the SCM section of my pom.xml:
<scm>
<connection>scm:git:git://github.com/tleese22/my-app.git</connection>
<developerConnection>scm:git:git#github.com:tleese22/my-app.git</developerConnection>
<url>http://github.com/tleese22/my-app</url>
</scm>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
</plugin>
Below is my .git/config:
[core]
repositoryformatversion = 0
filemode = true
logallrefupdates = true
bare = false
[branch "master"]
remote = origin
merge = refs/heads/master
[remote "origin"]
url = git#github.com:tleese22/my-app.git
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = git#github.com:tleese22/my-app.git
Here's the result of git show origin:
$ git remote show origin
Enter passphrase for key '/c/Users/Taylor Leese/.ssh/id_rsa':
* remote origin
Fetch URL: git#github.com:tleese22/my-app.git
Push URL: git#github.com:tleese22/my-app.git
HEAD branch: master
Remote branches:
gh-pages new (next fetch will store in remotes/origin)
master new (next fetch will store in remotes/origin)
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
$ git status
# On branch master
nothing to commit (working directory clean)
I have run into the same problem and I traced this to the fact that git is requiring a passphrase, but Maven has no way to specify an appropriate passphrase, so the process essentially hangs. Note that this problem is limited to Windows.
The solution is to run ssh-agent. This can be found in C:\Program Files (x86)\Git\bin\. After you run it, it outputs some environment variables that you need to set. For example:
SSH_AUTH_SOCK=/tmp/ssh-LhiYjP7924/agent.7924; export SSH_AUTH_SOCK;
SSH_AGENT_PID=2792; export SSH_AGENT_PID;
echo Agent pid 2792;
So, you need to place these in your environment:
C:\> set SSH_AUTH_SOCK=/tmp/ssh-LhiYjP7924/agent.7924
C:\> set SSH_AGENT_PID=2792
Then, you will need to add a passphrase for your particular key file. Generally, if you issued a command like git fetch origin master for your project, you will get a passphrase prompt like: Enter passphrase for key '/c/Users/Anthony Whitford/.ssh/id_rsa' -- that is the file that you need to register with the agent. So, the command is:
C:\> ssh-add "/c/Users/Anthony Whitford/.ssh/id_rsa"
It will prompt you for a passphrase, so enter it. You should see an Identity added message. Now, the agent knows the passphrase so that you will not be prompted to specify it anymore.
If you have multiple instances of command prompts, make sure that each command prompt has the appropriate SSH_AUTH_SOCK and SSH_AGENT_PID environment variables set. You can validate that this is working by running a command like ssh -v git#github.com and if you DO NOT get prompted for a passphrase, it is working!
Note that when you logoff, the ssh-agent will shut down and so when you log back in or restart your computer, you will need to repeat these steps. My understanding is that your passphrase is stored in memory, not persisted to disk, for security reasons.
The mvn release:prepare goal always runs in non-interactive mode, so you can't enter the ssh passphrase git is waiting for while pushing to the remote repository.
You can use an SSH agent to manage that, but if this problem only appears during the release process, there is another solution : preparing the release locally, and pushing the tag afterwards.
For this you have to use version 2.1+ of maven-release-plugin that comes with the pushChanges parameter.
mvn -DpushChanges=false release:prepare
By the way, your tag is created into your local GIT repository and you can then push it to the remote repository as usual, with a git push command.
This method is useful for Eclipse users because Eclipse comes with an embedded ssh-agent but this agent is not used by maven while performing a release:prepare, even when using eGit.
Considering the source of git builtin-push.c, that means that somehow, no remote are defined for the local Git repo used by the maven script.
static int do_push(const char *repo, int flags)
{
int i, errs;
struct remote *remote = remote_get(repo);
const char **url;
int url_nr;
if (!remote) {
if (repo)
die("bad repository '%s'", repo);
die("No destination configured to push to.");
}
As illustrated by this blog post, the maven config is not the all story.
~/foo/mikeci-archetype-springmvc-webapp$ git remote add origin git#github.com:amleggett/mikeci-archetype-springmvc-webapp.git
A remote add is still required, before specifying the maven scm parameters:
Updating the POM
For Maven to function effectively, you should always ensure that you include project VCS information in your POM file.
Now that we’ve added the archetype to a Git repository we can include the appropriate <scm> configuration:
<scm>
<connection>
scm:git:ssh://github.com/amleggett/${artifactId}.git
</connection>
<developerConnection>
scm:git:ssh://git#github.com/amleggett/${artifactId}.git
</developerConnection>
<url>
http://github.com/amleggett/${artifactId}
</url>
</scm>
The same blog post adds:
It’s important to understand the meaning of each of the child elements of <scm>.
The <connection> element defines a read-only url and
the <developerConnection> element a read+write url.
For both of these elements the url must adhere to the following convention:
scm:<scm implementation>:<scm implementation-specific path>
Finally, the <url> element content should point to a browsable location and for me this is the GitHub repository home page. Note that in all cases, I’m using an interpolated value which is my project artifactId.
One handy tip is that you can verify this configuration by using the maven-scm-plugin.
This plugin offers ‘vendor’ independent access to common VCS commands by offering a set of command mappings for the configured VCS. The validate goal should confirm all is well:
~/foo/mikeci-archetype-springmvc-webapp$ mvn scm:validate
[INFO] Preparing scm:validate
[INFO] No goals needed for project - skipping
[INFO] [scm:validate {execution: default-cli}]
[INFO] connectionUrl scm connection string is valid.
[INFO] project.scm.connection scm connection string is valid.
[INFO] project.scm.developerConnection scm connection string is valid.
[INFO] --------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
These are the exact sequence of commands I followed to get rid of this error
C:\Program Files (x86)\Git\bin>bash
bash-3.1$ eval 'ssh-agent -s'
SSH_AUTH_SOCK=/tmp/ssh-ZARFN11804/agent.11804; export SSH_AUTH_SOCK;
SSH_AGENT_PID=10284; export SSH_AGENT_PID;
echo Agent pid 10284;
bash-3.1$ exec ssh-agent bash
bash-3.1$ ssh-add "/c/Users/idntus/.ssh/id_rsa"
Enter passphrase for /c/Users/idntus/.ssh/id_rsa:
Identity added: /c/Users/idntus/.ssh/id_rsa (/c/Users/idntus/.ssh/id_rsa)
bash-3.1$ mvn release:prepare release:perform
The only thing which worked for me was specifying GIT user name and password as maven parameters:
mvn -Dusername=jenkins -Dpassword=******** release:prepare release:perform
To hide password in Jenkins output console I installed and configured Mask Passwords Plugin.
Yet another reason it could hang is if github.com isn't in the known_hosts file. SSH will therefore hang waiting for the user to accept authenticity of the host.
To add github.com to your known hosts just do a quick SSH to it: ssh github.com. The SSH client will then ask you to confirm the authenticity of the host. Type "Yes" and it'll say that its permanently added github.com to your list of known hosts.
I had faced the same problem, I had tried many ways but got to resolved it with below steps:
1. you need check git origin
2. update your pom.xml,find scm section,
change github ssh address the `:` to '/'
before
<scm>
<connection>scm:git:ssh://git#github.com:xxx/xxxin.git</connection>
<developerConnection>scm:git:ssh://git#github.com:xxx/xxxin.git</developerConnection>
<url>https://github.com/xxx/jenkins-xxx-plugin</url>
<tag>HEAD</tag>
</scm>
then
<scm>
<connection>scm:git:ssh://git#github.com/xxx/xxxin.git</connection>
<developerConnection>scm:git:ssh://git#github.com/xxx/xxxin.git</developerConnection>
<url>https://github.com/xxx/jenkins-xxx-plugin</url>
<tag>HEAD</tag>
</scm>
3. set ~/.m2/settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>maven.jenkins-ci.org</id> <!-- For parent 1.397 or newer; before this use id java.net-m2-repository -->
<username>your jenkins username</username>
<password>your jenkins password</password>
</server>
</servers>
4. then commit & push your changes
5. run mvn release:prepare release:perform
I had the same issue.
I tried all the above solutions and still it did not work.
That was because I was still doing one thing wrong: for the ssh commands I used git bash while for the maven command I used the command prompt. And there not all the git commands were available.
After adding the complete git bin folder to the PATH variable everything worked for me.