I'm trying to set up jenkins to run some pipelines for me. As part of my pipeline, I want to checkout a second git repository, which I am placing into a subdirectory of the workspace.
However, this pipeline step will fail on a clean workspace, with an error like:
! [new branch] develop -> origin/develop (unable to update local ref)
error: cannot lock ref 'refs/remotes/origin/master': unable to resolve reference 'refs/remotes/origin/master': Not a directory
From what I can tell, this is happening because git is failing to create the .git/refs/remotes/origin/master file (however it does manage to create the .git/refs/remotes/origin/ directory, which isn't created by the git init command).
Upon playing around, I can reproduce this issue in the docker container by creating a new empty directory and running
git init
git fetch --tags --force --progress -- {giturl} +refs/heads/*:refs/remotes/origin/*
which appears to be what the jenkins step is doing.
If I run the git fetch a second time, it will then succeed.
So far, this is all within a mounted volume in the container. If I try to recreate the problem not in a mounted container, I can't. The
git init
git fetch --tags --force --progress -- {giturl} +refs/heads/*:refs/remotes/origin/*
steps work as expected, meaning that something appears to be going wrong within the mounted volume for some reason.
Does anyone know what might causing these issues within the mounted volume?
Incidentally I also have a stage doing:
bat "\"C:/Program Files/LLVM/bin/clang-format.exe\" -n --style=file --fallback-style=none .\\Source\\*.c .\\Source\\*.cpp .\\Source\\*.h .\\Source\\*.hpp 2>&1 | python ./libraries/clang-to-junit.py ${WORKSPACE} Clang-Format > clang-format-results.xml"
bat "type clang-format-results.xml"
junit allowEmptyResults: true, skipOldReports: true, skipPublishingChecks: true, testResults: 'clang-format-results.xml'
which creates a clang-format-results.xml file to report results of clang format. However the junit step fails to find the file if it's newly created, despite the type command outputting the file just fine. Seems like this could be related also to filesystem issues...
Related
I have this command at the top of my pipeline file, and my build failed immediately in Jenkins while trying to resolve it:
#Library('MyLibrary') _
pipeline{
...
I also have this library setup in my global jenkins config. Triple checked it.
The Jenkins log is below... the internet says this happens when git.exe is misconfigured or not found. We have 100% verified git is installed on all the slaves. However, I suspect that this failing git clone is running somewhere else since the pipeline has not officially started yet (we don't see RUNNING ON: blah in the log).
So... Does it run this on the master? We have master set to 0 executors, and git is not installed there.
Is this problem solved as easily as installing git on the master? Or is there some other magical place where these #Library includes get cloned?
Here is the Jenkins log output, with names changed to protect the innocent:
Started by user Me
15:28:23 Connecting to my github url
Obtained Jenkinsfile from blah
Running in Durability level: MAX_SURVIVABILITY
Loading library MyLibrary#master
Examining <my github repo>
Attempting to resolve master as a branch
Resolved master as branch master at revision blah
No credentials specified
Cloning the remote Git repository
Cloning with configured refspecs honoured and without tags
Cloning repository <my repo url>.git
> git init /home/afolder/jenkins/workspace/<git repo name>#libs/MyLibrary # timeout=10
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Could not init /home/afolder/jenkins/workspace/<git repo name>#libs/MyLibrary
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:813)
...
Caused by: java.io.IOException: Cannot run program "git" (in directory
"/home/afolder/jenkins/workspace/<git repo name>#libs/MyLibrary"):
error=2, No such file or directory
Yes, by default it will run on the Jenkins master.
Please follow the link for more info.
You can read library file and give the file to writeFile pipeline step
writeFile(file:"foo.groovy", text: libraryResource("bar.groovy"))
"groovy foo.groovy"
I am building a system to do c++ cmake builds primarily. I have Jenkins firing the dynamic pods, firing off shell scripts, etc. But, I can't get it to checkout the code. Now, my Jenkinsfile launches a container that the actual compile is supposed to be run in. That "sub" container is tuned to compile C++ code. Now, I have jenkins running scripts and such in that pod, but, when i try
checkout scm
im getting errors saying
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git fetch --tags --force --progress git#gitlab.com:mystuff/hello-world-cmake.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: No user exists for uid 1000080000
fatal: Could not read from remote repository.
my home folder is the standard /home/jenkins and the workspace folder is there, etc, etc. But, when I dump the /etc/passwd file, the jenkins user isn't listed in it.
Whats the appropriate way to add the jenkins user to that file?
What image are you using for Jenkins slave? Does it have user jenkins? If it has you need to specify this in your spec for Jenkins slave:
spec:
securityContext:
runAsUser: 1000
UPDATE:
You cannot run default Jenkins image in Openshift, because Openshift runs containers as random user. You should run Jenkins from builtin Jenkins template "Jenkins Persistent". If you don't have this template and don't have Jenkins image stream - you can try to use image openshift/jenkins-2-centos7. See details at:
https://github.com/openshift/jenkins/issues/168
https://github.com/openshift/jenkins
I use continuous integration with Travis to run my unit tests on every commit. However, sometimes all I want to do is edit the README. Is there a way to skip Travis builds if all the changes are restricted to a whitelisted set of files?
There's no way to directly make Travis dynamically determine, based only on the type of file that has been changed, if it should run a build.
However, Travis will ignore any commit with [ci skip] or [skip ci] in the commit message.
Perhaps you could use a git hook (say prepare-commit-msg or similar) to append [ci-skip] to the commit message when only .md files have been modified.
In the git hook, you could detect this scenario with a command like git diff --exit-code --name-only -- . ':(exclude)*.md'.
In action:
$ git diff --name-only
README.md
$ git diff --exit-code --name-only -- . ':(exclude)*.md'
$ echo $?
0
If any non *.md files have been changed, the command will return 1, otherwise 0.
We are porting our Jenkins pipeline to work on Windows environments.
The Jenkins' master connects to our Windows remote -named winremote- using Cygwin sshd.
As described on this page, the Remote root directory of the node is given as a plain Windows path (in this case, it is set to C:\cygwin64\home\jenkins\jenkins-slave-dir)
This minimal pipeline example:
node("winremote")
{
echo "Entering Windows remote"
sh "ls -l"
}
fails with the error:
[Pipeline] echo
Entering Windows rmeote
[Pipeline] sh
[C:\cygwin64\home\jenkins\jenkins-slave-dir\workspace\proto-platforms] Running shell script
sh: C:\cygwin64\home\jenkins\jenkins-slave-dir\workspace\proto-platforms#tmp\durable-a739272f\script.sh: command not found
SSHing into the Windows remote, I was able to see that Jenkins actually created workspace subdirectory in C:\cygwin64\home\jenkins\jenkins-slave-dir, but it is left empty.
Is there a known way to use the sh pipeline step on such a remote ?
A PR from blatinville, that was merged a few hours after this question, solves this first issue.
Sadly, it introduces another problem, described in the ticket JENKINS-41225, with the error:
nohup: failed to run command 'sh': No such file or directory
There is a proposed PR for a quickfix of this issue.
Then there is a last problem with how the durable-task-plugin evaluate if a task is still alive using 'ps', with another PR fixing it.
Temporary solution
Until those (or equivalent) fixes are applied, one could compile a Cygwin compatible durable-task-plugin with the following commands:
git clone https://github.com/Adnn/durable-task-plugin.git -b cygwin_fixes
cd durable-task-plugin/
mvn clean install -DskipTests
Which notably generates target/durable-task.hpi file, which can be used to replace the durable-task.jpi file as installed by Jenkins in its plugins folder. It is then required to restart Jenkins.
In some jenkins shell command I create new git branch as follow:
git checkout -b new_branch
...
run more commands
..
sometimes running some commands is not successfull and the job exits.
Now when I run the job again it says that the branch new_branch already exists.
Is there any option in jenkins to cleans up the locally created branches every time when the job starts or something like that?
2 ways to go about it :
Run "git branch -d new_branch" to delete your local branch
Clean your workspace before checking out