I'm using ant to generate build parameters in the upstream job and passing them down using "Trigger Parameterized build on other projects". But the downstream job is not receiving them , even though both the builds are Restricted to the same node.
I have other jobs in the pipeline where the build parameter is passing but not when I'm moving from one stage to another.
Sample Output:
16:57:35 Running as SYSTEM
16:57:35 Setting version to: #89-NEXT from upstream version
16:57:35 [EnvInject] - Loading node environment variables.
16:57:35 Building remotely on Slave (wraith acceptance ios-slave integration javascript php7.1) in workspace /var/lib/jenkins/workspace/in-release-services
16:57:35 using credential gourav-git
16:57:35 > git rev-parse --is-inside-work-tree # timeout=10
16:57:35 Fetching changes from the remote Git repository
16:57:35 > git config remote.origin.url git#github.com:InterNations/in.git # timeout=10
16:57:35 Cleaning workspace
16:57:35 > git rev-parse --verify HEAD # timeout=10
16:57:35 No valid HEAD. Skipping the resetting
16:57:35 > git clean -fdx # timeout=10
16:57:35 Fetching upstream changes from git#github.com:InterNations/in.git
16:57:35 > git --version # timeout=10
16:57:35 using GIT_SSH to set credentials gourav-git-jenkins
16:57:35 > git fetch --no-tags --progress git#github.com:InterNations/in.git +refs/heads/*:refs/remotes/origin/*
16:57:37 > git rev-parse origin/$GIT_APP_REVISION^{commit} # timeout=10
16:57:37 > git rev-parse $GIT_APP_REVISION^{commit} # timeout=10
16:57:37 ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
16:57:37 ERROR: Build step failed with exception
16:57:37 java.io.IOException: Cannot retrieve Git metadata for the build
16:57:37 at org.jenkinsci.plugins.github.util.BuildDataHelper.getCommitSHA1(BuildDataHelper.java:87)
16:57:37 at org.jenkinsci.plugins.github.status.sources.BuildDataRevisionShaSource.get(BuildDataRevisionShaSource.java:32)
16:57:37 at org.jenkinsci.plugins.github.status.GitHubCommitStatusSetter.perform(GitHubCommitStatusSetter.java:135)
16:57:37 Caused: org.jenkinsci.plugins.github.common.CombineErrorHandler$ErrorHandlingException
16:57:37 at org.jenkinsci.plugins.github.common.CombineErrorHandler.handle(CombineErrorHandler.java:74)
16:57:37 at org.jenkinsci.plugins.github.status.GitHubCommitStatusSetter.perform(GitHubCommitStatusSetter.java:164)
16:57:37 at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:79)
16:57:37 at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
16:57:37 at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
16:57:37 at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
16:57:37 at hudson.model.Build$BuildExecution.post2(Build.java:186)
16:57:37 at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
16:57:37 at hudson.model.Run.execute(Run.java:1841)
16:57:37 at com.tikal.jenkins.plugins.multijob.MultiJobBuild.run(MultiJobBuild.java:76)
16:57:37 at hudson.model.ResourceController.execute(ResourceController.java:97)
16:57:37 at hudson.model.Executor.run(Executor.java:429)
Expected Output:
Running as SYSTEM
Setting version to: #6558-deploy/2020-03-03 from upstream version
[EnvInject] - Loading node environment variables.
Building remotely on docker-ci-040 (database test integration php7.1 guestlist-app) in workspace /var/lib/jenkins/workspace/in-release-services
using credential github-internations-jenkins
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url git#github.com:InterNations/in.git # timeout=10
Cleaning workspace
> git rev-parse --verify HEAD # timeout=10
Resetting working tree
> git reset --hard # timeout=10
> git clean -fdx # timeout=10
Fetching upstream changes from git#github.com:InterNations/in.git
> git --version # timeout=10
using GIT_SSH to set credentials GitHub internations-jenkins SSH user
> git fetch --no-tags --progress git#github.com:InterNations/in.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse 54ba1520d2a11276fc3d564c5b5312388abddd10^{commit} # timeout=10
Checking out Revision 54ba1520d2a11276fc3d564c5b5312388abddd10 (detached)
Enabling Git LFS pull
> git config core.sparsecheckout # timeout=10
> git checkout -f 54ba1520d2a11276fc3d564c5b5312388abddd10
> git config --get remote.origin.url # timeout=10
using GIT_SSH to set credentials GitHub internations-jenkins SSH user
> git lfs pull origin
Related
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.
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.
Problem Statement: I am getting error like "stderr: remote: Invalid username or password." for Jenkins build.
My Jenkinsfile is as follows:
node {
stage('SCM Checkout') {
git 'https://github.com/xxxxxxxxxxxx/java-app'
}
stage('Compile Package'){
// Get path of Maven Home
def MavenHome = tool name: 'MVN_HOME', type: 'maven'
sh "${MavenHome}/bin/mvn package"
}
}
I have saved my credentials in Jenkins as below:
My Jenkins looks like below:
Unfortunately, I am getting error/log output as below:
Checking out git https://github.com/xxxxxxxxxxx/java-app into /var/lib/jenkins/workspace/My-app-Jenkinspipeline#script to read Jenkinsfile
using credential githubcredentials
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/xxxxxxxxxxx/java-app # timeout=10
Fetching upstream changes from https://github.com/xxxxxxxxxxx/java-app
> git --version # timeout=10
using GIT_ASKPASS to set credentials Github Credentials
> git fetch --tags --force --progress -- https://github.com/xxxxxxxxxxx/java-app +refs/heads/*:refs/remotes/origin/* # timeout=10
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 691f79125928ce480176fd04e96c4f61297c8051 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 691f79125928ce480176fd04e96c4f61297c8051 # timeout=10
Commit message: "Added Checkout step"
> git rev-list --no-walk 371a72a8024ce467f287f5297efaa5662c3c5181 # timeout=10
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/My-app-Jenkinspipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (SCM Checkout)
[Pipeline] git
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/xxxxxxxxxxx/java-app # timeout=10
Fetching upstream changes from https://github.com/xxxxxxxxxxx/java-app
> git --version # timeout=10
> git fetch --tags --force --progress -- https://github.com/xxxxxxxxxxx/java-app +refs/heads/*:refs/remotes/origin/* # timeout=10
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from https://github.com/xxxxxxxxxxx/java-app
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:909)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1131)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1167)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:125)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:93)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:80)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- https://github.com/xxxxxxxxxxx/java-app +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/xxxxxxxxxxx/java-app/'
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2430)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2044)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:81)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:569)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:907)
... 11 more
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE
Please assist as I want to understand why I am getting an incorrect username and password even though I can login with the same credentials to Github
To get SCM Checkout working we need to add credentials. I did as below:
git changelog: false, credentialsId: 'githubcredentials', poll: false, url: 'https://github.com/xxxxxxxxxxxx/java-app'
My first stage in Jenkinsfile(scripted pipeline) is checkout scm, which gives a brief description about the GitHub checkouts and all revision related things which I don't want to display in Jenkins console output.
Is it possible to hide this in console output of Jenkins.
following console output is from Jenkins for checkout scm step, which I want to hide
Cloning the remote Git repository
Cloning repository https://github.com/forpi/cherry-pik.git
> git init /home/ubuntu/.jenkins/workspace/Dummy-project # timeout=10
Fetching upstream changes from https://github.com/forpi/cherry-pik.git
> git --version # timeout=10
> git fetch --tags --progress https://github.com/forpi/cherry-pik.git +refs/heads/*:refs/remotes/origin/*
> git config remote.origin.url https://github.com/forpi/cherry-pik.git # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url https://github.com/forpi/cherry-pik.git # timeout=10
Fetching upstream changes from https://github.com/forpi/cherry-pik.git
> git fetch --tags --progress https://github.com/forpi/cherry-pik.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision b80c4d6b655429d7f84347b4192461cc3d68283e (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f b80c4d6b69c429d7f84347b4192461cc3d68283e
> git branch -a -v --no-abbrev # timeout=10
> git checkout -b master b80c4d6b655429d7f84347b4192461cc3d68283e
Commit message: "lets try this again"
Checkout scm has option to provide arguments like this and there is a quietoperation mode availabe
checkout([$class: 'SubversionSCM',
additionalCredentials: [],
locations: [[cancelProcessOnExternalsFail: true,
credentialsId: '234243-45654-234randomstuff',
depthOption: 'infinity',
ignoreExternalsOption: true,
local: '.',
remote: 'https://starkindustries/ironman/superGlueForThanosFingers/repo']],
**quietOperation: true,**
workspaceUpdater: [$class: 'UpdateUpdater']])
You can also try this
checkout scm &> /dev/null
This will suppress stdout and stderr, unless the git command fails
or
If you want to checkout using git
git checkout origin master --quiet
git checkout origin master --q
Which is an available option in git.
Hope it helps :)
Try this handy plugin:
https://wiki.jenkins.io/display/JENKINS/Collapsing+Console+Sections+Plugin
It may not be super neat but, it can get the work done.
Why does jenkins doesn't execute my jenkinsfile? The console ouput of my build is this:
20:06:19 Started by GitLab push by
20:06:19 Building in workspace /var/jenkins_home/workspace/repo
20:06:19 [WS-CLEANUP] Deleting project workspace...
20:06:19 [WS-CLEANUP] Done
20:06:19 Cloning the remote Git repository
20:06:19 Cloning repository
20:06:19 > git init /var/jenkins_home/workspace/ # timeout=10
20:06:19 Fetching upstream changes from https://gitlab.com/
20:06:19 > git --version # timeout=10
20:06:19 using GIT_ASKPASS to set credentials
20:06:19 > git fetch --tags --progress https://gitlab.com/t+refs/heads/*:refs/remotes/origin/*
20:06:21 > git config remote.origin.url https://gitlab.com/ # timeout=10
20:06:21 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
20:06:21 > git config remote.origin.url https://gitlab.com/ # timeout=10
20:06:21 Fetching upstream changes from https://gitlab.com/
20:06:21 using GIT_ASKPASS to set credentials
20:06:21 > git fetch --tags --progress https://gitlab.com/ +refs/heads/*:refs/remotes/origin/*
20:06:22 skipping resolution of commit remotes/origin/jenkins, since it originates from another repository
20:06:22 > git rev-parse refs/remotes/origin/jenkins^{commit} # timeout=10
20:06:22 > git rev-parse refs/remotes/origin/origin/jenkins^{commit} # timeout=10
20:06:22 Checking out Revision 44f2afa95f961b5b28a482516abf05a17180ea48 (refs/remotes/origin/jenkins)
20:06:22 > git config core.sparsecheckout # timeout=10
20:06:22 > git checkout -f 44f2afa95f961b5b28a482516abf05a17180ea48
20:06:22 Commit message: "chore: test jenkins"
20:06:22 > git rev-list --no-walk dfff4c2214daa01de600086d6d28cf8f9d53cdc5 # timeout=10
20:06:22 Finished: SUCCESS
In my jenkins file I have this sample pipeline
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building..'
}
}
stage('Test') {
steps {
echo 'Testing..'
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
}
}
}
}
Is there something I missed?
You need to choose pipeline type after click new item on jenkins page, rather than choose freestyle/maven type. Input a name and click 'OK', then choose pipeline from SCM