Jenkins - Couldn't find any revision to build - jenkins

I have been using Jenkins for a few days, and before: I used the GITEA plugin
Now that I have switched my projects to GitBucket, I would like to use the "Build by Webhook" Feature.
I followed many tutorials, and now : i'm stuck on a simple/big problem.
In advance, I'm sorry to have to blur the sensitive links, I know it can be annoying.
Here is the full error :
using credential 10
Wiping out workspace first.
Contributing variables:
Cloning the remote Git repository
Cloning repository https://MY_GITBUCKET/git/MY_USERNAME/MY_PROJECT
> git init /Jenkins/workspace/GitBUcket # timeout=10
Fetching upstream changes from https://MY_GITBUCKET/git/MY_USERNAME/MY_PROJECT
> git --version # timeout=10
> git --version # 'git version 2.20.1'
using GIT_ASKPASS to set credentials Utilisateur GitBucket Perso
> git fetch --tags --force --progress -- https://MY_GITBUCKET/git/MY_USERNAME/MY_PROJECT +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url https://MY_GITBUCKET/git/MY_USERNAME/MY_PROJECT # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
Avoid second fetch
Seen 0 remote branches
> git show-ref --tags -d # timeout=10
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
Finished: FAILURE
Here is my configuration on Jenkins : https://i.stack.imgur.com/jdlTt.png
Thank you very much in advance
EDIT : My only branche is master --> https://i.imgur.com/lXJ0xyN.png

This is what you can try:
Manage Jenkins -> Global Tool Configuration -> Git
Check if Path to Git executable is set: C:\PATH\git.exe
Dashboard -> select your job -> Configure -> Source Code Management -> select Git
Insert your Repository URL and Credentials(Optional) then under Branches to build change */master to */main.

Related

Jenkins - restarting a pipeline on a different node fails on 'git checkout' (git plugin)

There is a job that gets triggered on pull request creation or update. I do not have the permissions to edit the job itself. Sometimes it will fail due to network connection problems, timeouts, etc. In this case I'd like to be able to restart the build with the same parameters. However in case of a restart, the build fails when checking out. It also skips the merge step for some reason
Is it possible to force the git-plugin to 'start fresh' on every build through Jenkinsfile? I was hoping that 'CleanBeforeCheckout' extension would solve my problem, but unfortunately this did not help.
Now for the details. Here's what my checkout step looks like in Jenkinsfile:
gitBranches = [[name: 'origin/pull-requests/**'], [name:"origin/$fromBranch"]]
gitExtensions = [
[
$class: 'UserIdentity',
email: email,
name: name
],
[
$class: 'PreBuildMerge',
options:
[
fastForwardMode: 'FF',
mergeRemote : 'origin',
mergeTarget : toBranch
]
],
[
$class: 'CleanBeforeCheckout',
deleteUntrackedNestedRepositories: false
]
]
println "Cloning repo with url '$gitUrl'"
checkout changelog: true, poll: true, scm: [
$class : 'GitSCM',
branches : gitBranches,
doGenerateSubmoduleConfigurations: false,
extensions : gitExtensions,
gitTool : 'Default',
submoduleCfg : [],
userRemoteConfigs : [[credentialsId: credentialsId, url: gitUrl]]
]
On the first run, the git checkout never fails. Here's what it looks like:
Selected Git installation does not exist. Using Default
The recommended git tool is: NONE
using credential <credential_id>
Cloning the remote Git repository
Cloning repository <repo_url>
> git init /home/jenkins/agent/workspace/<workspace_id> # timeout=10
Fetching upstream changes from <repo_url>
> git --version # timeout=10
> git --version # 'git version 2.7.1'
using GIT_ASKPASS to set credentials
> git fetch --tags --progress <repo_url> +refs/heads/*:refs/remotes/origin/* # timeout=10
Avoid second fetch
Merging Revision <my_feature_hash> (origin/feature/my_feature) to origin/develop, UserMergeOptions{mergeRemote='origin', mergeTarget='develop', mergeStrategy='DEFAULT', fastForwardMode='FF'}
Checking out Revision <target_hash> (origin/develop)
Commit message: "Merge commit '<my_feature_hash>' into HEAD"
First time build. Skipping changelog.
> git config remote.origin.url <repo_url> # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
<...>
Seen 27 remote branches
> git show-ref --tags -d # timeout=10
> git rev-parse origin/develop^{commit} # timeout=10
> git config core.sparsecheckout # timeout=10
> git checkout -f origin/develop # timeout=10
> git remote # timeout=10
> git config --get remote.origin.url # timeout=10
using GIT_ASKPASS to set credentials
> git merge --ff <my_feature_hash> # timeout=10
> git rev-parse HEAD^{commit} # timeout=10
<...>
Seen 27 remote branches
> git show-ref --tags -d # timeout=10
> git config core.sparsecheckout # timeout=10
> git checkout -f <target_hash> # timeout=10
However, when restarting the build from the Jenkins UI, the job fails with such output:
Selected Git installation does not exist. Using Default
The recommended git tool is: NONE
using credential <credential id>
Cloning the remote Git repository
Cloning repository <repository_url>
> git init /home/jenkins/agent/workspace/<workspace_id> # timeout=10
Fetching upstream changes <repository_url>
> git --version # timeout=10
> git --version # 'git version 2.7.1'
using GIT_ASKPASS to set credentials
> git fetch --tags --progress <repository_url> +refs/heads/*:refs/remotes/origin/* # timeout=10
Avoid second fetch
Checking out Revision <target_hash> (origin/develop)
> git config remote.origin.url <repository_url> # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
<...>
Seen 27 remote branches
> git show-ref --tags -d # timeout=10
> git config core.sparsecheckout # timeout=10
> git checkout -f <target_hash> # timeout=10
Could not checkout <target_hash>
The problem supposedly arises because the git-plugin saves the previous build state somehow. This is bad because my builds will run on different nodes every time.

Manual git pull is able to copy latest master repository code but when I pull from Jenkins build job old master is getting pulled

Manual git pull is able to copy latest master repository code but when I pull from Jenkins build job old master is getting pulled.
we can see old pull request in below logs but not the latest.
Please help me on this.
Thanks
01:48:26 > C:\Program Files\Git\cmd\git.exe rev-parse "refs/remotes/origin/refs/remotes/origin/master^{commit}" # timeout=10
01:48:26 > C:\Program Files\Git\cmd\git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
01:48:27 Checking out Revision b971a3367b2e015d83a34d0ba2cb92a3bf1e916a (refs/remotes/origin/master)
01:48:27 Enabling Git LFS pull
01:48:27 > C:\Program Files\Git\cmd\git.exe config core.sparsecheckout # timeout=10
01:48:27 > C:\Program Files\Git\cmd\git.exe checkout -f b971a3367b2e015d83a34d0ba2cb92a3bf1e916a # timeout=10
01:48:31 > C:\Program Files\Git\cmd\git.exe config --get remote.origin.url # timeout=10
01:48:31 using GIT_SSH to set credentials Manny Bitbucket Key
01:48:31 > C:\Program Files\Git\cmd\git.exe lfs pull origin # timeout=10
01:49:06 Commit message: "Merged in LicenseTestsScenario (pull request #41)"

How to run a command from the GitHub directory that Jenkins clones into?

I put "make" in Jenkins's Execute Shell, following the tutorial here https://github.com/jbankes/Hello_Jenkins, but Jenkins does not run the make from the underlying Github repository, as shown in the error message below.
What is the right way to demand Jenkins to run "make" from its monitored GitHub repository?
Running as SYSTEM
Building in workspace /var/jenkins_home/workspace/test003
The recommended git tool is: NONE
No credentials specified
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/zhoulaifu/Hello_Jenkins # timeout=10
Fetching upstream changes from https://github.com/zhoulaifu/Hello_Jenkins
> git --version # timeout=10
> git --version # 'git version 2.20.1'
> git fetch --tags --force --progress -- https://github.com/zhoulaifu/Hello_Jenkins +refs/heads/*:refs/remotes/origin/* # timeout=10
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision bc3931a313e4f3945c257ae3247e63265b1debb7 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f bc3931a313e4f3945c257ae3247e63265b1debb7 # timeout=10
Commit message: "Otherside (#5)"
> git rev-list --no-walk bc3931a313e4f3945c257ae3247e63265b1debb7 # timeout=10
[test003] $ /bin/sh -xe /tmp/jenkins2704537311990415428.sh
+ make
make: *** No targets specified and no makefile found. Stop.
Build step 'Execute shell' marked build as failure
Finished: FAILURE
In the repository Make file located inside original folder. So to be able to run Make you need navigate to it.
After git clone execute cd original/ and then run Make.

Simple Jenkins application to show gcc version

I am after a simple Jenkin application to show gcc version after each push to bitbucket.
Here is the Jenkinsfile:
pipeline {
agent { docker { image 'kernelci/build-gcc-7_arm:3.3.3' } }
stages {
stage('build') {
steps {
sh 'gcc --version'
}
}
}
}
Bitbucket
Repository Settings/Post Webhooks:
http://jenkins.SOMEADDRESS:8080/bitbucket-scmsource-hook/notify
After each push, the build does not start automatically but not a problem. I starts the builds manually.
However, The Jenkin build output result looks like this
Started by user MY_USERNAME
[Office365connector] No webhooks to notify
Building on master in workspace c:\w\PROJECTNAME
> git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git.exe config remote.origin.url http://bb.MYWEBSITE.COM/scm/bbb/MYREPO.git # timeout=10
Fetching upstream changes from http://bb.MYWEBSITE.COM/scm/bbb/MYREPO.git
> git.exe --version # timeout=10
using GIT_ASKPASS to set credentials Credentials for Jenkins in Bitbucket
> git.exe fetch --tags --progress http://bb.MYWEBSITE.COM/scm/bbb/MYREPO.git +refs/heads/*:refs/remotes/origin/*
Seen branch in repository origin/feature/LAST_BRANCH
Seen branch in repository origin/feature/BRANCH_A
Seen branch in repository origin/feature/BRANCH_B
Seen branch in repository origin/feature/BRANCH_C
Seen branch in repository origin/feature/BRANCH_D
Seen branch in repository origin/feature/BRANCH_E
Seen branch in repository origin/feature/BRANCH_F
Seen branch in repository origin/feature/BRANCH_G
Seen 8 remote branches
> git.exe show-ref --tags -d # timeout=10
Checking out Revision e3152f566543dfb813c6e33ac0d1099da7ec26a6 (origin/LAST_BRANCH)
> git.exe config core.sparsecheckout # timeout=10
> git.exe checkout -f e3152f566543dfb813c6e33ac0d1099da7ec26a6
Commit message: "Merge branch 'feature/BRANCH_A' into LAST_BRANCH"
First time build. Skipping changelog.
[Office365connector] No webhooks to notify
Finished: SUCCESS
It does not look like loading a dock in 4 seconds. I do not see any gcc version on the screen either. Where is the problem from?
Is it from Jenkinsfile?

Jenkins Job Build Failure

After job build starts in jenkins my git-lab server's memory becomes full. Job is successful after restarting the Jenkins server.Jenkins has become too slow Sometimes Error comes with signal 9 also. Thank-you in advance. I have attached the log of the failed build.
started by user ME
Building in workspace /var/lib/jenkins/workspace/my_Project
using credential ABC
> /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> /usr/bin/git config remote.origin.url git#myrepo:root/My_Project.git # timeout=10
Fetching upstream changes from git#myrepo:root/My_Project.git
> /usr/bin/git --version # timeout=10
using GIT_ASKPASS to set credentials
> /usr/bin/git fetch --tags --progress git#myrepo:root/My_Project.git +refs/heads/*:refs/remotes/origin/*
> /usr/bin/git rev-parse refs/remotes/origin/My_Project_Develop^{commit} # timeout=10
> /usr/bin/git rev-parse refs/remotes/origin/origin/My_Project_Develop^{commit} # timeout=10
Checking out Revision fbd8fcef97895366d1d08bccb22615712d1f9ef0 (refs/remotes/origin/My_Project_Develop)
> /usr/bin/git config core.sparsecheckout # timeout=10
> /usr/bin/git checkout -f fbd8fcef97895366d1d08bccb22615712d1f9ef0
Commit message: "Update features of Software."
> /usr/bin/git rev-list --no-walk fbd8fcef97895366d1d08bccb22615712d1f9ef0 # timeout=10
Checking for pre-build
Executing pre-build step
Checking if email needs to be generated
No emails were triggered.
[My_Project] $ /bin/sh -xe /tmp/jenkins6218118938138193412.sh
+ id -un
root
+ SSH_OPTS='-o StrictHostKeyChecking=no -o ConnectTimeout=5'
+ sudo git checkout My_Project_Develop
Previous HEAD position was fbd8fce... Update features of Software.
Switched to branch 'My_Project_Develop'
Your branch is behind 'origin/My_Project_Develop' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
Build step 'Execute shell' marked build as failure
Discard old builds...
#1040 is removed because status FAILURE is not to be kept
Checking for post-build
Performing post-build step
Checking if email needs to be generated
No emails were triggered.
Finished: FAILURE
You need to pull the My_Project_Develop branch, checkout is only switching to this branch. Your branch is locally behind the server.
The message is clear:
Your branch is behind 'origin/My_Project_Develop' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
Usually this is done by Jenkins. I need more info how you run this job.

Resources