Getting Issues while VSTS Integration with Jenkins using Service Hooks - jenkins

[As part of CI,I want to integrate VSTS with Jenkins using Service Hooks,Here are the Steps i perform.
1.After selecting Jenkins Service option, I am entering the Jenkins details as per below image.
2.Jenkins base URL, User name, User API Token are entered but Build Textbox is not allowing me enter any value.
Build Error Log using Build and Release:-
2017-06-23T12:46:02.5702001Z ##[section]Starting: Build
2017-06-23T12:46:02.5721999Z Current agent version: '2.119.1'
2017-06-23T12:46:03.0032004Z ##[section]Starting: Initialize Job
2017-06-23T12:46:03.0122005Z Prepare build directory.
2017-06-23T12:46:03.0431992Z Set build variables.
2017-06-23T12:46:03.0471996Z Download all required tasks.
2017-06-23T12:46:03.0601994Z Downloading task: JenkinsQueueJob
2017-06-23T12:46:03.7031992Z Downloading task: JenkinsDownloadArtifacts
2017-06-23T12:46:05.7861997Z Downloading task: PublishTestResults
2017-06-23T12:46:05.9391998Z Downloading task: PublishBuildArtifacts
2017-06-23T12:46:06.1041998Z ##[section]Finishing: Initialize Job
2017-06-23T12:46:06.1351993Z ##[section]Starting: Get Sources
2017-06-23T12:46:06.1711981Z Syncing repository: MyFirstProject (TfsGit)
2017-06-23T12:46:06.1761997Z Prepending Path environment variable with directory containing 'git.exe'.
2017-06-23T12:46:06.1842000Z ##[command]git version
2017-06-23T12:46:06.4442001Z git version 2.12.0.windows.1
2017-06-23T12:46:06.4561989Z ##[command]git init "d:\a\1\s"
2017-06-23T12:46:06.5122094Z Initialized empty Git repository in d:/a/1/s/.git/
2017-06-23T12:46:06.5151998Z ##[command]git remote add origin https://ramandogra.visualstudio.com/_git/MyFirstProject
2017-06-23T12:46:06.5371993Z ##[command]git config gc.auto 0
2017-06-23T12:46:06.5571999Z ##[command]git config --get-all http.https://ramandogra.visualstudio.com/_git/MyFirstProject.extraheader
2017-06-23T12:46:06.5761994Z ##[command]git config --get-all http.proxy
2017-06-23T12:46:06.6061997Z ##[command]git -c http.extraheader="AUTHORIZATION: bearer ********" fetch --tags --prune --progress origin
2017-06-23T12:46:07.4221999Z ##[command]git checkout --progress --force refs/remotes/origin/master
2017-06-23T12:46:07.4431999Z error: pathspec 'refs/remotes/origin/master' did not match any file(s) known to git.
2017-06-23T12:46:07.6841986Z ##[error]Git checkout failed with exit code: 1
2017-06-23T12:46:07.6881995Z ##[section]Finishing: Get Sources
2017-06-23T12:46:07.6901995Z ##[section]Starting: Post Job Cleanup
2017-06-23T12:46:07.6951999Z Cleaning any cached credential from repository: MyFirstProject (Git)
2017-06-23T12:46:07.6992000Z ##[command]git remote set-url origin https://ramandogra.visualstudio.com/_git/MyFirstProject
2017-06-23T12:46:07.7211998Z ##[command]git remote set-url --push origin https://ramandogra.visualstudio.com/_git/MyFirstProject
2017-06-23T12:46:07.7401991Z ##[section]Finishing: Post Job Cleanup
2017-06-23T12:46:07.7461997Z ##[section]Finishing: Build
PS: I am first time user of VSTS.

This is mainly caused your jenkins base URL is a local address, such as http://computername:8080 (or http://ip:8080). But the URL can’t be reached by others.
Do below things to check if local URL can be used:
In http://localhost:8080/configure, use the Jenkins URL as Jenkins base URL for service hook.
Turn off firewall for your local machine.

Related

Jenkins #Library resolution failing due to git.exe not existing, but where?

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"

Jenkins user not in passwd on dynamic jnlp slave in kubernetes

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

Bitbucket webhook generating build on the wrong GIT repository

I want to trigger a pipeline on my OpenShift when an event occurs on bitbucket (push for example). I configured a webhook correctly following the instructions on Openshift documentation pages. Although I had to change my Openshift template of my pipeline which generated some conflicts.
The BuildConfig looks like this:
- apiVersion: "v1"
kind: "BuildConfig"
metadata:
name: "${SERVICE_NAME}-pipeline"
spec:
source:
contextDir: '${APPLICATION_GIT_JENKINSFILE_REPO_CONTEXT_DIR}'
git:
ref: master
uri: '${APPLICATION_GIT_JENKINSFILE_REPO}'
sourceSecret:
name: git-secret
type: Git
strategy:
jenkinsPipelineStrategy:
jenkinsfilePath: Jenkinsfile
triggers:
type: "Bitbucket"
bitbucket:
secretReference:
name: "mysecret"
So, on the 'source' component I reference a git repository where my Jenkinsfile is located. This way I can have many pipelines with only a single Jenkinsfile centralized. Note that this repo is completly different from the location of the api where I'm configuring the webhook.
This approach although fails on an automatic trigger due to the fact that the payload sent to the Openshift has the commit id of the changes of the respective api repository. Openshift (I don't know why) tries to associate that commit with the repo that is present on this template (Jenkinsfile repo).
The logs are the following:
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url http://jenkinsfile-repo.git # timeout=10
Fetching upstream changes from http://jenkinsfile-repo.git
> git --version # timeout=10
using GIT_ASKPASS to set credentials git-secret
> git fetch --tags --progress http://jenkinsfile-repo.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse 79370e4fa88f19c693d85d82fbdbed77620d048b^{commit} # timeout=10
hudson.plugins.git.GitException: Command "git rev-parse 79370e4fa88f19c693d85d82fbdbed77620d048b^{commit}" returned status code 128:
stdout: 79370e4fa88f19c693d85d82fbdbed77620d048b^{commit}
stderr: fatal: ambiguous argument '79370e4fa88f19c693d85d82fbdbed77620d048b^{commit}': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2016)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1984)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1980)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1612)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1624)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.revParse(CliGitAPIImpl.java:809)
at hudson.plugins.git.GitAPI.revParse(GitAPI.java:316)
at hudson.plugins.git.RevisionParameterAction.toRevision(RevisionParameterAction.java:98)
at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:1070)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1187)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:113)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:144)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:67)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:303)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE
There we can see the behavior I tried to explain, the '79370e4fa88f19c693d85d82fbdbed77620d048b' was the commit id on the api repo, which OpenShift is trying to associate with the jenkinsfile repo.
If I could for example ignore the payload the problem wouldn't exist.
Thanks for the help.
I don't think you require put type: git(duplicate) and also try using https:// bitbucket url,
source:
contextDir: '${APPLICATION_GIT_JENKINSFILE_REPO_CONTEXT_DIR}'
git:
ref: master
uri: '${APPLICATION_GIT_JENKINSFILE_REPO}'
sourceSecret:
name: git-secret
type: Git *****remove and try ?
I managed to implement a workaround, although I still don't understand why the behavior I specified previously occurs.
Basically the current solution looks like this:
The openshift template references the GIT repository of the respective API, and that repository has a Jenkinsfile of his own, which is the same for every API. Although, the only thing this Jenkinsfile does is to call a groovy script that is centralized in a separate GIT repository and is declared as a shared library in Jenkins.
This way if we must change something, a stage of a pipeline for example, we only need to change in a single location, which was the objective from the begginning.

How to checkout a Bitbucket Git-LFS repo in Jenkins?

I have a Git LFS setup on our Bitbucket server, and can clone it on my Mac since I'm the owner.
Now I'm trying to set this up so a Jenkins job can clone the repo, and so on the SCM section I have
Repository URL: git#server.company.com:user/path/repo.git
Credentials: uernamePwCreds
It can get to the repo fine, but when it tries to checkout a Git-LFS file, it gets the following access error. See the Permission denied (publickey) error on last line.
FATAL: Could not checkout 104e35fb26dc1d3ed1689523cccb6e97829c0feb
hudson.plugins.git.GitException: Command "git checkout -f 104e35fb26dc1d3ed1689523cccb6e97829c0feb" returned status code 128:
stdout:
stderr: Downloading MarcomLite/lib/jets3t-0.6.1/cockpit-0.6.1.jar (144 KB)
Error downloading object: MarcomLite/lib/jets3t-0.6.1/cockpit-0.6.1.jar (716be41): Smudge error: Error downloading MarcomLite/lib/jets3t-0.6.1/cockpit-0.6.1.jar (716be4107b362e413dc1ae29dc88e9b79e680def2c725ecc2d73268c4ea66e75): batch request: Permission denied (publickey).: exit status 255
How do I setup the "Git-LFS-specific" level authentication?
I don't want to use a Jenkinsfile for now.
Try adding "Additional Behaviours" -> "Git LFS pull after checkout" in the Git section of the SCM configuration for your job.

MS Build Failure on Jenkins

I am new to Jenkins CI. However the issue looks very easy enough but its not working for me. My source code is in GIT and i am using Git repository for that.
I am getting the error below.
Thanks in Advance.
Started by user abc
Building on master in workspace /var/lib/jenkins/workspace/Hello World
git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
git config remote.origin.url
Fetching upstream changes from
git --version # timeout=10
using .gitcredentials to set credentials
git config --local credential.helper store --file=/tmp/git7943155421179786207.credentials # timeout=10
git fetch --tags --progress +refs/heads/:refs/remotes/origin/
git config --local --remove-section credential # 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 833228fa50173e7977b4d5ee86c1385b5c6494be (refs/remotes/origin/master)
git config core.sparsecheckout # timeout=10
git checkout -f 833228fa50173e7977b4d5ee86c1385b5c6494be
git rev-list 833228fa50173e7977b4d5ee86c1385b5c6494be # timeout=10
Path To MSBuild.exe: msbuild.exe
Executing the command msbuild.exe NimbusAutomation.sln from /var/lib/jenkins/workspace/Hello World
[Hello World] $ msbuild.exe ABCAutomation.sln
Build step 'Build a Visual Studio project or solution using MSBuild' changed build result to FAILURE
Build step 'Build a Visual Studio project or solution using MSBuild' marked build as failure
Warning: this build has no associated authentication, so build permissions may be lacking, and downstream projects which cannot even be seen by an anonymous user will be silently skipped
Finished: FAILURE
This can be caused by not configuring a jobs authorization policy correctly.
Check either the downstream job to see its configuration, or go to
Manage Jenkins-> Configure Global Security -> Access Control for Builds -> Configure Build Authorizations in Project Configuration
And check the global settings.
After finding the parent settings, go to the project giving the error select the same configuration in the section that looks like :
If this still does not work, you might also need to make sure that the user has the adequate permissions if you are using matrix based security.
Manage Jenkins-> Configure Global Security -> Authorization
And in the authorization matrix make sure the necessary user has build permissions
See also
Authorize project plugin
How To Configure Access Control For Builds
Thanks. I did all the advised settings above, it only resulted in Warning message to disappear, the build still fails.
The build works fine on my local Command prompt when i pass - msbuild.exe NimbusAutomation.sln but still fails on jenkins...
Path To MSBuild.exe: msbuild.exe
Executing the command msbuild.exe msbuild.exe NimbusAutomation.sln NimbusAutomation.sln from /var/lib/jenkins/workspace/Hello World
[Hello World] $ msbuild.exe msbuild.exe NimbusAutomation.sln NimbusAutomation.sln
Build step 'Build a Visual Studio project or solution using MSBuild' changed build result to FAILURE
Build step 'Build a Visual Studio project or solution using MSBuild' marked build as failure
Finished: FAILURE

Resources