In my jenkins file failing at below command
Code :
stage('Release') {
steps {
sh '/opt/maven/bin/mvn --batch-mode release:clean release:prepare release:perform'
}
}
stage('Update Rel') {
steps {
sh 'git push https://xxxx:password#github.com/dxtrsd/maven-multi-module-example.git HEAD:master'
}
Build failure :
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:3.0.0-M1:prepare (default-cli) on project multi: Unable to commit files
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] fatal: could not read Username for 'https://github.com': No such device or address
[ERROR] -> [Help 1]
[ERROR]
Following "Bootstrap your CI with Jenkins and GitHub" from Michael Wanyoike, you need to have entered your GitHub credentials first:
Then you need to select that credential under your URL (the image shows a SSH URL, but in your case, use the HTTPS URL)
I fixed this issue with providing user and password in developer connection url in block in the POM.xml file
Related
I'm trying to copy files using scp command from jenkins (ci/cd). But i got permission denied error. If i'm trying manually from diffrent servers, its all done, at the same time i tried the same command in jenkins exes command, then i got error.
Configure > Build > execute shell
and the console output is like below,
[nginx_server] $ /bin/sh -xe /tmp/jenkins7685256768444698.sh
scp 111 ubuntu#34.229.202.9:/home/ubuntu Permission denied, please try again. Permission denied, please try again. ubuntu#34.229.202.9:
Permission denied (publickey,password). lost connection Build step
'Execute shell' marked build as failure Finished: FAILURE
if anyone know the solution, please answer...
Add your ssh key as a secret to Jenkins.
In your pipeline use sshagent:
pipeline {
stages {
stage('Stage_name') {
steps {
script {
sshagent (credentials: ['secret_name']) {
sh "scp ... "
}
}
}
}
}
}
I have a private GitHub Rust project that depends on another private GitHub Rust project and I want to build the main one with Jenkins. I have called the organization Organization and the dependency package subcrate in the below code.
My Jenkinsfile looks something like
pipeline {
agent {
docker {
image 'rust:latest'
}
}
stages {
stage('Build') {
steps {
sh "cargo build"
}
}
etc...
}
}
I have tried the following in Cargo.toml to reference the dependency, it works fine on my machine
[dependencies]
subcrate = { git = "ssh://git#ssh.github.com/Organization/subcrate.git", tag = "0.1.0" }
When Jenkins runs I get the following error
+ cargo build
Updating registry `https://github.com/rust-lang/crates.io-index`
Updating git repository `ssh://git#github.com/Organization/subcrate.git`
error: failed to load source for a dependency on `subcrate`
Caused by:
Unable to update ssh://git#github.com/Organization/subcrate.git?tag=0.1.0#0623c097
Caused by:
failed to clone into: /usr/local/cargo/git/db/subcrate-3e391025a927594e
Caused by:
failed to authenticate when downloading repository
attempted ssh-agent authentication, but none of the usernames `git` succeeded
Caused by:
error authenticating: no auth sock variable; class=Ssh (23)
script returned exit code 101
How can I get Cargo to access this GitHub repository? Do I need to inject the GitHub credentials onto the slave? If so, how can I do this? Is it possible to use the same credentials Jenkins uses to checkout the main crate in the first place?
I installed the ssh-agent plugin and updated my Jenkinsfile to look like this
pipeline {
agent {
docker {
image 'rust:latest'
}
}
stages {
stage('Build') {
steps {
sshagent(credentials: ['id-of-github-credentials']) {
sh "ssh -vvv -T git#github.com"
sh "cargo build"
}
}
}
etc...
}
}
I get the error
+ ssh -vvv -T git#github.com
No user exists for uid 113
script returned exit code 255
Okay, I figured it out, No user exists for uid error is because of a mismatch between the users in the host /etc/passwd and the container /etc/passwd. This can be fixed by mounting /etc/passwd.
agent {
docker {
image 'rust:latest'
args '-v /etc/passwd:/etc/passwd'
}
}
Then
sshagent(credentials: ['id-of-github-credentials']) {
sh "cargo build"
}
Works just fine
I wrote a stage in a jenkins pipeline in order to push a docker image to a registry, but pipeline doesn't abort when docker login command fails :
make push BUILD_ID=733
for i in tomcat ; do cd $i ; make login && make push TAG=latest && make push ; cd - ; done
make[1]: Entering directory `/home/jenkins/workspace/CTO/CSF/Common/CSF-DOCKER/tomcat'
sudo docker login -u **** -p "****" csf-docker-candidate.repo.lab.pl.alcatel-lucent.com
Error response from daemon: Login: {
"errors" : [ {
"status" : 400,
"message" : "Unsupported docker v1 repository request for 'csf-docker-candidate'"
} ]
} (Code: 400; Headers: map[Date:[Mon, 13 Nov 2017 11:35:21 GMT] Server:[Artifactory/5.4.6] X-Artifactory-Id:[ff6eb7375fefa75b:-9fef662:15e7accbf81:-7ffd] Content-Type:[application/json]])
make[1]: *** [login] Error 1
make[1]: Leaving directory `/home/jenkins/workspace/CTO/CSF/Common/CSF-DOCKER/tomcat'
/home/jenkins/workspace/CTO/CSF/Common/CSF-DOCKER
[Pipeline] End of Pipeline
Finished: SUCCESS
what thing to add in order to abort the pipeline when the docker command fails;
thanks in advance
Pipeline does not fail, because your bash command succeeds. failure of your make command is hidden by success of "cd" after semicolon. You should make your command to exit loop on error and then fail whole script - see similar question here: https://unix.stackexchange.com/questions/241178/how-can-i-get-this-script-to-error-exit-based-on-result-of-for-loop
I am getting error in Jenkins at final step of build.
Error is:Failed to deploy artifacts, could not transfer artifact.
Failed to transfer file Artifactory URL.
Return code is 400 -> bad request.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project :
Failed to deploy artifacts: Could not transfer artifact from/to snapshots (Artifactory URL): Failed to transfer file: Artifactory URL/project.jar.
Return code is: 400, ReasonPhrase: Bad Request. -> [Help 1]
Please let me know what may cause this issue. Any help would be appreciated.
I am trying to setup https://spring.io/guides/gs/spring-boot-docker/#initial with my environment, which has a private registry server #
el-qa-docker.x.x.x:18445
my build.gradle has the following relevant content:
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.3.RELEASE")
classpath('se.transmode.gradle:gradle-docker:1.2')
classpath ('org.codehaus.groovy:groovy-backports-compat23:2.3.5')
}
group = 'james'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'docker'
task buildDocker(type: Docker, dependsOn: build) {
push = true
applicationName = jar.baseName
dockerfile = file('src/main/docker/Dockerfile')
doFirst {
copy {
from jar
into stageDir
}
}
}
when I run: $gradle build buildDock
I get build FAILURE, with:
$ gradle build buildDock
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:findMainClass
:jar
:bootRepackage
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
:buildDocker FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':buildDocker'.
> Docker execution failed
Command line [docker build -t skahmed/gs-spring-boot-docker:latest /Users/skahmed/devops/TOOLS/DOCKER/gs-spring-boot-docker/initial/build/docker] returned:
Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 16.243 secs
any ideas, on where do I specify docker's internal registry which can be used with Gradle.
I tried:
docker {
useApi true
hostUrl 'el-qa-docker.x.x.x:18445'
apiUsername 'james'
}
as provided by https://github.com/Transmode/gradle-docker
but that gives a different error:
$ gradle build buildDock
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:findMainClass
:jar
:bootRepackage
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
:buildDocker FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':buildDocker'.
> Port is invalid: -1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1.389 secs
I tried : build.gradle
docker {
//useApi true
hostUrl 'el2-dt-docker.uscis.dhs.gov:18445'
apiUsername 'skahmed'
}
and
task buildDocker(type: Docker, dependsOn: build) {
push = true
applicationName = jar.baseName
//applicationName = 'el2-dt-docker.uscis.dhs.gov:18445/skahmed/gs-spring-boot-docker'
//applicationName = 'gs-spring-boot-docker'
dockerfile = file('src/main/docker/Dockerfile')
doFirst {
copy {
from jar
into stageDir
}
}
}
but get:
:buildDocker FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':buildDocker'.
> Docker execution failed
Command line [docker push skahmed/gs-spring-boot-docker:latest] returned:
Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
You can specify your private Docker registry as part of your Docker image name e.g.:
el-qa-docker.x.x.x:18445/skahmed/gs-spring-boot-docker
Please make sure your Docker daemon is aware about private registry.