I've configured a Jenkins job which is monitoring a TFS git repository and is supposed to trigger a build when a code is changed (pushed).
Things I've done to configure the solution:
I've created a service hook for Jenkins on the TFS repository.
I've installed Team Foundation Server Plug-in and VS Team Services Continuous Deployment on Jenkins and configured the jobs like so:
Under "Source code management"
I chose Team Foundation Version Control (TFVC) and configured it like so:
Collection URL: https://company.visualstudio.com/defaultcollection
Project path: $/Wilhelm/_git/NWilhelm
Credentials: Automatic (I've also tried with Manual creds and got the same result)
Then, In "Manage Jenkins -> Configure system", under TFS/Team Services, I've configured:
Collection URL: https://company.visualstudio.com
Credentials: Selected the correct user which has access to the repo
Enable Push Trigger for all jobs: checked
And clicked save.
These are the tests I've done:
I ran the build manually:
Started by user Itai
Building remotely on jenkins-windows-slave (windows-slave) in workspace c:\jenkins\workspace\iis-deploy-new
Querying for remote changeset at '$/Wilhelm/_git/NWilhelm' as of 'D2017-03-19T15:39:58Z'...
Query returned no result!
FATAL: null
java.lang.NullPointerException
at hudson.plugins.tfs.model.Project.extractChangesetNumber(Project.java:276)
at hudson.plugins.tfs.model.Project.getRemoteChangesetVersion(Project.java:271)
at hudson.plugins.tfs.model.Project.getRemoteChangesetVersion(Project.java:287)
at hudson.plugins.tfs.TeamFoundationServerScm.recordWorkspaceChangesetVersion(TeamFoundationServerScm.java:359)
at hudson.plugins.tfs.TeamFoundationServerScm.checkout(TeamFoundationServerScm.java:308)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1278)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:604)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
at hudson.model.Run.execute(Run.java:1728)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:404)
Finished: FAILURE
That's the error I get when I run the job through Jenkins.
I've pushed a change to the repo expecting it to trigger a build on Jenkins but nothing happened.
I've checked the TFS webhook log on the job but it's empty.
Any idea what I'm doing wrong?
"Team Foundation Version Control (TFVC)" option is used to get files from TFVC version control system while you are using Git version control system. Please select "Git" option under "Source code management" and then try again.
Related
I am running my builds in Kubernetes agents, so poll SCM won't work since the agents will be removed once the build is completed.
I am using plastic SCM and I found there is an option called poll on the controller for it in the readme.
I am using the cm commands in my Jenkins file for the SCM environment variables.
Eg:-
scmvars = cm(
branch: "${Branch_Name}",
changeset: "${Change_Set}",
repository: "${Repo_Name}",
server: "${Plastic_Server_Url}",
cleanup: 'DELETE'
)
Later I print the variables as:
println scmvars.PLASTICSCM_BRANCH, scmvars.PLASTICSCM_CHANGESET_ID
But I didn't see the Poll on controller option in the pipeline syntax and in the documentation.
For one of my projects that I have on GitHub, I wanted to build it as a docker image and push it to my docker hub. The project is a sbt one with a Scala codebase.
Here is how my JenkinsFile is defined:
#!groovy
node {
// set this in Jenkins server under Manage Jenkins > Credentials > System > Global Credentials
docker.withRegistry('https://hub.docker.com/', 'joesan-docker-hub-credentials') {
git credentialsId: '630bd271-01e7-48c3-bc5f-5df059c1abb8', url: 'https://github.com/joesan/monix-samples.git'
sh "git rev-parse HEAD > .git/commit-id"
def commit_id = readFile('.git/commit-id').trim()
println comit_id
stage "build" {
def app = docker.build "Monix-Sample"
}
stage "publish" {
app.push 'master'
app.push "${commit_id}"
}
}
}
When I tried to run this from my Jenkins server, I get the following error:
java.io.FileNotFoundException
at jenkins.plugins.git.GitSCMFile$3.invoke(GitSCMFile.java:167)
at jenkins.plugins.git.GitSCMFile$3.invoke(GitSCMFile.java:159)
at jenkins.plugins.git.GitSCMFileSystem$3.invoke(GitSCMFileSystem.java:161)
at org.jenkinsci.plugins.gitclient.AbstractGitAPIImpl.withRepository(AbstractGitAPIImpl.java:29)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.withRepository(CliGitAPIImpl.java:65)
at jenkins.plugins.git.GitSCMFileSystem.invoke(GitSCMFileSystem.java:157)
at jenkins.plugins.git.GitSCMFile.content(GitSCMFile.java:159)
at jenkins.scm.api.SCMFile.contentAsString(SCMFile.java:338)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:101)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:59)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:232)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:404)
Finished: FAILURE
Since this is running inside a VM on Azure, I thought the VM was not able to reach outside, but that seems not to be the case as I was able to ssh into the VM and git pull from the Git repo. So what is the problem here? How could I make this work?
for me unchecking "lightweight checkout" fixed the issue
I experienced the exact same error. My setting:
Pipeline build inside a dockerized Jenkins (version 2.32.3)
In the configuration of the job, I specified a check out into a subdirectory: Open the configuration, e.g. https://myJenkins/job/my-job/configure. At the bottom, see section Pipeline -> Additional Behaviours -> Check out into a sub-directory with Local subdirectory for repo set to, e.g., my-sub-dir.
Expectation: Upon check out, the Jenkinsfile ends up in my-sub-dir/Jenkinsfile.
Via the option Script path, you configure the location of the Jenkinsfile so that Jenkins can start the build. I put my-sub-dir/Jenkinsfile as value.
I then received the exception you pasted in your question. I fixed it by setting Script Path to Jenkinsfile. If you don't specify a sub-directory for check out, then still try double checking values for Script Path.
Note: I have another Jenkins instance at work. There I have to specify Script Path including the custom check out sub-directory (as mentioned in Expectation above).
GO TO Job-->Config-->Pipline and uncheck checkbox lightweight checkout"
lightweight checkout : selected, try to obtain the Pipeline script contents >directly from
the SCM without performing a full checkout. The advantage of this mode
is its efficiency; however, you will not get any changelogs or polling
based on the SCM. (If you use checkout scm during the build, this will
populate the changelog and initialize polling.) Also build parameters
will not be substituted into SCM configuration in this mode. Only
selected SCM plugins support this mode.
I am trying to set up a job in Jenkins using this p4 plugin. I successfully installed the plugin. While I am trying to run perforce commands in execute shell I got below exception.
[workspace] $ /bin/sh -xe /tmp/hudson6165069639422088214.sh
+ echo 'Trunk Release is r2017.1.0'
Trunk Release is r2017.1.0
++ /usr/local/perforce/p4 -P E208C3B005AB1F8E7C138F7156F857EC counter cos_sso_trunk_build_number
User jenkins doesn't exist.
+ BLD_NUM=
Build step 'Execute shell' marked build as failure
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered
Finished: FAILURE
I have included P4 Configuration, Its working fine. But above error is when I will try P4 commands in console earlier Perforce plugin (old) its working fine
It's expecting an account for the user "jenkins". Either create an account for that user, or use an existing user.
On the Configure page, under Source Code Management-->Perforce Software Perforce Credentials, select Add to add the user information.
I am using Jenkins to run jobs and want to create/update tickets in JIRA, whenever build fails. I have downloaded JIRA plugin, Jira Issue Updater, JiraTestResultReporter plugins and configured URL and credentials, under Manage Jenkins/Configure System.
In the job am running, under Post-build Actions, I added 'Create Jira Issue' with project key, assignee name etc and 'Jira Test Result Reporter' with all required credentials.
I get the following error in the console:
ERROR: Publisher 'Jira Test Result Reporter' aborted due to exception:
java.lang.NoSuchMethodError: hudson.model.AbstractBuild.getTestResultAction()Lhudson/tasks/test/AbstractTestResultAction;
at JiraTestResultReporter.JiraReporter.perform(JiraReporter.java:105)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:726)
at hudson.model.Build$BuildExecution.post2(Build.java:185)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:671)
at hudson.model.Run.execute(Run.java:1769)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:374)
Finished: FAILURE
Any idea whats going wrong? Is it not able to find the project? I have access to create ticket in the project specified, in jira.
It is generally possible to create tickets in JIRA programmatically, for example via their REST API.
Regarding your error, this behavior was introduced when the method signature of getTestResultAction() changed to return an Action instead of an AbstractTestResultAction.
The effect on the JiraTestResultReporter plugin is a known issue and is tracked at JENKINS-25140.
The error was fixed in the source of the plugin a while ago, but is still pending a release.
Solution:
As a workaround, Daniel Beck suggests to build and install a snapshot of the current JiraTestResultReporter plugin which seems to solve this particular error (see comments to the Jenkins ticket mentioned above).
I have configured jenkins with gerrit trigger plugin to validate every commit we push to gerrit.
I am expecting this trigger to include my latest change with original repo and make a build.
But, it is cloning only repo project and compiling without my change.
Below is my configuration settings for gerrit trigger in jenkins.
Refspec: $GERRIT_REFSPEC
Branches to build: $GERRIT_BRANCH
Build trigger: Gerrit event
Trigger on: patch set created
Gerrit project: added project and branch
Below is the build output message
Triggered by Gerrit: http://ci-test1/22
Building on master in workspace /var/lib/jenkins/jobs/Build_Adserver_4.7/workspace
Checkout:workspace / /var/lib/jenkins/jobs/Build_Adserver_4.7/workspace - hudson.remoting.LocalChannel#733aee56
Using strategy: Default
Last Built Revision: Revision 701a75ef38aa191ac1b806c48e6b3451671888f6 (ads/4.7)
Fetching changes from 1 remote Git repository
Fetching upstream changes from abc
Commencing build of Revision 701a75ef38aa191ac1b806c48e6b3451671888f6 (ads/4.7)
Checking out Revision 701a75ef38aa191ac1b806c48e6b3451671888f6 (ads/4.7)
[workspace] $ /bin/sh -xe /tmp/hudson1375188638196718521.sh
+ echo 'Started Build'
Started Build
+ echo ..................
..................
+ echo 'Build Finished'
Build Finished
Finished: SUCCESS
Here 701a75ef38aa191ac1b806c48e6b3451671888f6 is HEAD of repo branch and 8cbda558adcad4fb7eb714e0b3fb98a6fbf5811c is the SHA-id of my latest change trigged the build.
I verified from jenkins workspace also, it doesn't include my change.
sorry if I am missing any information to mention. Please let me know
please help me if I am missing anything here.
Using Jenkins 1.532.2 Git Client Plugin 1.6.2 Git Plugin 2.0.1 Git Trigger 2.11.0
Here are the steps for configuring the Gerrit Trigger (from memory, hopefully all works fine):
Install the plugin(s) "Gerrit Trigger", "Git Plugin" and "Git Client Plugin"
In the main jenkins config (HOME->Manage Jenkins), click on Gerrit Trigger.
Create the server and configure it. Use "Test Connection" to be sure it works.
At the end, under "Control" press "start" (No idea what that does or if it's actually needed, but I did that).
Go to your project's config (MYPROJECT->Configure)
Check "Gerrit event" under "Build Triggers"
In the newly added menu, select your server, your triggers, etc.
For Gerrit Project I used "Plain" with "MYPROJECT" as pattern
For Branch, I used "Path" and "**" as pattern (builds all branches)
Under "Source Code Management" (up from triggers in my UI), click on "Git"
Set the Repository URL, here $USER matches for me, but otherwise write the correct user $GERRIT_SCHEME://$USER#$GERRIT_HOST:$GERRIT_PORT/$GERRIT_PROJECT
Specify a branch: $GERRIT_BRANCH
Under "Repositories" on the right, click Advanced, for "Refspec" enter $GERRIT_REFSPEC
Click Add right below, and select "Strategy for choosing what to build"
Select "Gerrit Trigger"
Not very intuitive but it should work. I suggest making sure the correct SHA1 Ids are being built.
If run into Error stderr: fatal: Couldn't find remote ref $GERRIT_REFSPEC
You have to change the Choosing Strategy to Gerrit Trigger
Go to the configuration page of your job and then click on the 2nd Advanced button under the git section. Almost at the bottom there is a Choosing Strategy that you will need to change to Gerrit Trigger
This will cause Git to fetch the correct version for your build
Fixing small issues in Lewis answer, change the values to the following to ensure the latest SHA1 is built.
branch: $GERRIT_REFSPEC
REFSPEC: $GERRIT_REFSPEC:$GERRIT_REFSPEC
I am using Jenkins 2.15 and faced the Issue and got resolved with following settings.
In Git Advances add Refspec : $GERRIT_REFSPEC
Branches to build : $GERRIT_BRANCH.
In Addititional behaviors section select Strategy for choosing what to build and select gerrit Trigger.