I am new to use the spinnaker. I have set up the spinnaker with the helm chart in my k8s cluster. Everything is working fine. Now I have a new requirement to set up the notification for the spinnaker pipeline (Success/failure). But the requirement is tricky.
I read out about Spinnaker and Jenkins to post the success/failure status. Spinnaker has a notification mechanism to notify for each stage/pipeline about success/failure. We can set up this notification. Jenkins has the same mechanism. But the question is when the spinnaker pipeline successfully completed then it triggers the Jenkins job to post the spinnaker pipeline status on the portal. I have created a Jenkins stage that is successful triggers the Jenkins job but it is not catching the status or events from the spinnaker pipeline. In case, job spinnaker pipeline failed, it will not trigger the Jenkins to post the failure message. I tried to find out the solution but unable to do it. If anyone knows how to fix this issue, Please guide me or write me the solution in detail here.
Thanks
You do not need to create Jenkins stage in the same pipeline which you are monitoring. You can create additional Pipeline in Spinnaker which receive trigger from target pipeline. All you need is configure trigger in that new pipeline:
"triggers": [
{
"application": "demo-app",
"enabled": true,
"pipeline": "demo-pipe",
"status": [
"successful",
"failed"
],
"type": "pipeline"
}
]
You can extract required information (e.g. status) about upstream pipeline from this trigger.
If post the pipeline status on the internal portal in your terms means to send an HTTP Request than you should consider a Webhook Stage.
In runtime you have whole parent pipeline context in your downstream and can get it status with expression like ${trigger.parentExecution.status} to provide it in your request.
Is there a way to show the Jenkins build status on my project's GitHub Readme.md?
I use Jenkins to run continuous integration builds. After each commit it ensures that everything compiles, as well as executes unit and integration tests, before finally producing documentation and release bundles.
There's still a risk of inadvertently committing something that breaks the build. It would be good for users visiting the GitHub project page to know the current master is in that state.
Ok, here's how you can set up Jenkins to set GitHub build statuses. This assumes you've already got Jenkins with the GitHub plugin configured to do builds on every push.
Go to GitHub, log in, go to Settings, Developer Settings, Personal access tokens and click on Generate new token.
Check repo:status (I'm not sure this is necessary, but I did it, and it worked for me).
Generate the token, copy it.
Make sure the GitHub user you're going to use is a repository collaborator (for private repos) or is a member of a team with push and pull access (for organization repos) to the repositories you want to build.
Go to your Jenkins server, log in.
Manage Jenkins → Configure System
Under GitHub Web Hook select Let Jenkins auto-manage hook URLs, then specify your GitHub username and the OAuth token you got in step 3.
Verify that it works with the Test Credential button. Save the settings.
Find the Jenkins job and add Set build status on GitHub commit to the post-build steps
That's it. Now do a test build and go to GitHub repository to see if it worked. Click on Branches in the main repository page to see build statuses.
You should see green checkmarks:
In the meanwhile the UI of Jenkins and GitHub has changed a bit and it took me a while to figure out how to configure Jenkins now correctly. The explanation here is based on Jenkins version 2.121.1.
I also assume that you have already configured your Jenkins Job be triggered by a webhook or by polling.
Those are the steps that I have taken to get it working:
Configure Github: Create Personal Access Token with OAuth Scope repo:status
Configure Jenkins: Configure System and add the OAuth Secret as a GitHub Server - use Secret Text as an authentication method to put the OAuth Secret in there.
Configure your Jenkins Job: Add Set GitHub commit status as Post-build action. Set the Status Result to One of the default messages and statuses.
Check your result on GitHub: Check if you get the build status and build execution duration on your GitHub commit.
Configure Github
Configure Jenkins
Configure Jenkins Job
Result
You will now see the status for your commits and branches:
What I did is quite simple:
Install the Hudson Post Task Plugin
Create a Personal Access Token here : https://github.com/settings/tokens
Add a Post Task Plugin that always put success
curl -XPOST -H "Authorization: token OAUTH TOKEN" https://api.github.com/repos/:organization/:repos/statuses/$(git rev-parse HEAD) -d "{
\"state\": \"success\",
\"target_url\": \"${BUILD_URL}\",
\"description\": \"The build has succeeded!\"
}"
Add a Post Task Plugin that will put failure if "marked build as failure"
curl -XPOST -H "Authorization: token OAUTH TOKEN" https://api.github.com/repos/:organization/:repos/statuses/$(git rev-parse HEAD) -d "{
\"state\": \"failure\",
\"target_url\": \"${BUILD_URL}\",
\"description\": \"The build has failed!\"
}"
You can also add a call to pending at the beginning of tests
curl -XPOST -H "Authorization: token OAUTH TOKEN" https://api.github.com/repos/:organization/:repos/statuses/$(git rev-parse HEAD) -d "{
\"state\": \"pending\",
\"target_url\": \"${BUILD_URL}\",
\"description\": \"The build is pending!\"
}"
This plugin should work: https://wiki.jenkins-ci.org/display/JENKINS/Embeddable+Build+Status+Plugin
You should be able to embed badges like this into your README.md file:
The Commit Status API allows you to see the "Repo Statuses API".
And since April 26th 2013, you now can see the build status on your GitHub repo branch page:
That means it is another way, by visiting the GitHub project page, to see those statuses instead of having only Jenkins.
Starting April 30th, 2013, the API endpoint for commit statuses has been extended to allow branch and tag names, as well as commit SHAs.
There's also the plugin Embeddable Build Status that will give you a badge URL that you can post in your README.md file, and it looks like this:
If you have the GitHub plugin installed on your Jenkins, you can do it in the Post build actions like this:
Add the below line in your README.md file and change both URLs according to your Jenkins project.
[![Build Status](https://jenkins../..project/lastBuild/buildStatus)](https://jenkins../..project/lastBuild/)
In regards with setting up Jenkins and GitHub's protected branch. I'm using Jenkins 2.6, and these are the steps I did to make it work:
On your repository's GitHub webpage:
Navigate to Settings > Branches.
Under Protect branches, click on
the Choose a branch drown down menu and select the branch you want
to set as a Protected branch.
Enable the options as needed.
On the Jenkins Server:
(Make sure you have the Git and GitHub Plugin installed)
Navigate to Manage Jenkins > Configure System.
Under GitHub, set the API URL to https://api.github.com. Though this is the default value.
Select your generated token for the Credentials. If you haven't generated a token yet, click on Advanced... then on Additional actions, you can convert your login and password to token and use it as your credential.
Also, make sure the GitHub account that your Jenkins is using is a collaborator for the repository. I've set it with write permission level.
Hope this helps.
I followed the directions from Alex and it worked.
But, for GitHub Enterprise you need to modify the API URL when adding the server to Jenkins.
For example, if your company is creditcard.com, your URL would be
https://github.creditcard.com/api/v3/
Edit:
I'm no longer using this approach, please use one of the other answers.
Update: what I ended up doing, for our specific case: (above answers were great - thanks!)
Because our build server is not on the internet, we have a script to publish the build status to the gh-pages branch in github.
Start of build stamps failing
End of build stamps success
Project runs after main project to publish results -> build-status, API docs, test reports and test coverage.
GitHub caches images, so we created .htaccess file, that instructs a short cache timeout for the build-status image.
Put this in the directory with the build-status image:
ExpiresByType image/png "access plus 2 minutes"
Here's the build script. The target that publishes to gh-pages is '--publish.site.dry.run'
With less than 400 lines of config, we have:
Compile checks
unit & integration tests
Test Reports
Code Coverage Reports
API Docs
Publishing to Github
. . and this script can be run in or outside of Jenkins, so that:
Developers can run this script before commit, reducing the chance of a broken build that impacts others.
A failure is easy to reproduce locally.
The Results:
Project main page has the build status, updated after each build, along with latest API Docs, test results and test coverage.
Jently updates your GitHub commit status (as described by vonc), but unfortunately they have yet to implement the Repo Status API.
For pipeline projects, you can use the post section like so:
void setBuildStatus(String message, String state) {
step([
$class: "GitHubCommitStatusSetter",
reposSource: [$class: "ManuallyEnteredRepositorySource", url: "https://github.com/my-user/my-repo"],
contextSource: [$class: "ManuallyEnteredCommitContextSource", context: "ci/jenkins/build-status"],
errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "UNSTABLE"]],
statusResultSource: [ $class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: message, state: state]] ]
]);
}
pipeline {
agent any
triggers {
githubPush()
}
stages {
stage('Hello') {
steps {
echo 'Hello World'
}
}
}
post {
success {
setBuildStatus("Build succeeded", "SUCCESS");
}
failure {
setBuildStatus("Build failed", "FAILURE");
}
}
}
Just change "https://github.com/my-user/my-repo" to meet your GitHub repository.
Reference: How to set GitHub commit status with Jenkinsfile NOT using a pull request builder
I am adding to this answer, and also to this one. They have answered the question, but they didn't give us a proper intuition about the problem
So, here are my intuitions:
We need to add status to our GitHub commit. This status is based upon the results of our Jenkins build.
To do this, we need to give Jenkins access to the GitHub API, not to the repo. We do this through OAuth, and we can create the token going to the GitHub settings → Developer settings → Personal access tokens. Then for a public GitHub repository just check repo:status, and for a private repository, check the whole repository section
After creating your access token you need to add it to your Jenkins server:
Copy and paste the access token to the GitHub plugin section settings, under your Jenkins configurations
Create a GitHub server. It defaults to api.github.com. And add the access token as a secret text credentials.
The last step is to add a post build settings when you create your pipeline.
Resources:
Here is a section of a YouTube video in which he goes over the above steps.
Read about OAuth
My user is receving the following error when promoting a JAR file from snapshot repository to release repository using artifactory promotion plugin. Please help on how to avoid this error.
Performing dry run promotion (no changes are made during dry run) ...
ERROR: Promotion failed during dry run (no change in Artifactory was done): HTTP/1.1 400 Bad Request
{
"messages" : [ {
"level" : "ERROR",
"message" : "The repository 'XXXXXX' rejected the path 'XX/XX/XXXXX/XX/XXXX/2.1-SNAPSHOT/malin-modular-2.1-20180125.094354-1.jar' due to a conflict with its snapshot/release handling policy."
}, {
"level" : "INFO",
"message" : "Skipping promotion status update: item promotion was completed with errors and warnings."
} ]
}
Little information to guess the reason but assuming this is with Maven repositories...
Each repository is configured to receive either:
only snapshots (i.e. version ends with "-SNAPSHOT" or a timestamp)
only releases (any version except if it ends with "-SNAPSHOT" or a timestamp)
both snapshots and releases (any version is accepted, I don't really recommend this)
This is configured in the details of the local repository, see this page
When you configure your promotion, you configure a move from a repository to another, but you still have to respect the capabilities of your repositories.
So my guess is that you are trying to promote a snapshot version to a repository that only accepts release versions
I suggest you that you set up
a snapshot local repository (e.g. 'dev')
a release local repository (e.g. 'release')
a release local repository for promoted element (e.g. 'gold')
And use
'dev' to push the results of your continuous build on your CI
'release' to push the results of your release process on your CI
'gold' as the target of your promotion process from 'release' to 'gold'
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.