Access properties of old builds in a Workflow job - jenkins

Is it possible to access the last failed build and the last successful build informations within a Workflow Job?
The information I need is the start time of those builds.

This was reposted and some options made available in JENKINS-29563. In particular I suggest reading the Snippet Generator documentation for currentBuild.

Related

How to run a specific job with GithubActions

When some of my GithubActions jobs has failed, I don't have the possibility to re-run the specific failing job, only "Re-run all jobs". Is there any way to achieve this?
This is all working now in GitHub, the caveat is you can only run "specific jobs in a workflow run up to 30 days after its initial run."
https://docs.github.com/en/actions/managing-workflow-runs/re-running-workflows-and-jobs#reviewing-previous-workflow-runs
I’m the workflow file you want to be able to manually trigger, add workflow_dispatch to the “on:” clause. Then go to the actions tab on github, select the action and you should see the option to manually run it. Before asking this type of question, please use google next time. When looking for “triggger github workflow manually” the first result is a article written by github on how to do it. https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow
Unfortunately, re-run a single job is not possible yet.
Their repository does have an Open Issue to implement this feature.
https://github.com/actions/runner/issues/432
The good news is it is officially in their roadmap and is scheduled for Q1 2022.
https://github.com/github/roadmap/issues/271

Jenkins - Discard old builds according to success/failed status

Jenkins Freestyle.
Is it possible to set a different discard behavior according to the build status? Just like a TFS build has. For example:
Failed - keep 12 last builds
Success - keep 5 last builds
After exploring this plugin, its not sufficient.
Upto now there is no direct plugin to do that. You can check this source code and write one for your own. discard-old-build-plugin. It's not that much hard to write on seeing its source code. If not you can write a program in Jenkins Script Console to do that. Here I am attaching a sample script link to do that.

Using Jira to trigger a Jenkins build

I have a strange use case here I know, but basically I have a CI / CD solution that starts be a developer creating a zip file of a set of resources. This zip is then sucked in to SVN via the tools internal programs.
Currently the solution works, using the FSTRigger to poll for an updated zip. When it see it, then the process kicks off and we're happy.
going forward I'd like the builds to be triggered by a Jira job reaching a certain status and have been looking at the Jira trigger plugin. It looks like it will help satisfy me with regards the triggering of the build and passing data from Jira to Jenkins to use for delivery notes etc. However it would still depend on the zip file being in a certain location to be picked up.
I'm wondering if it's possible to attach the zip to the Jira task and then as part of the task status hitting 'build' kick off the Jenkins job and copy the zip so it can be picked up by by the Jenkins build task.
for reasons to complex to mention, checking the zip into svn first won't really work.
When your Jenkins build is triggered via jira-trigger-plugin, you would be able to access JIRA_ISSUE_KEY environment variable that contains the JIRA issue which status has changed.
With the JIRA issue key, you can hit Get Issue JIRA REST API to retrieve the issue details. The issue details would contain the attachment information, which would then be able to be used for downloading the zip in Jenkins.

Can you ask for user input for TFS 2015 CI build?

This seems simple enough, but I can't find a solution for this online.
I am integrating SonarQube into our build definitions that get triggered on check in. I want the version SonarQube uses to be tied back to the project number defined by the business side of things.
Ideally, I would like to be able to prompt the user for input. When you go to check in and it kicks off the build, it would ask you for the project number to be used as the version for SonarQube. Is this something TFS 2015 supports?
User input for build definitions
As far as I know, build definitions that are not manually triggered do not prompt for user input. A prompt allowing users to set build variables is shown for manually triggered builds from the VSTS web page.
SonarQube project version
I would recommend against you using the build or assembly version in your build tasks. This is because the SonarQube concept of version is quite different from the build concept. SonarQube uses versions as a baselining mechanism / to determine the leak period. If you up the version number often, the leak period is going to be too short to be actionable.
I'd recommend keeping the SonarQube project version in sync with your release schedule instead.
The short answer to this question is no, there is no way to prompt for input on a non-manually triggered CI build.
Here's what we did to work around this:
I wrote a Powershell script to read a config file and set the values to environment variables exposed to later build steps. Those variables are then what are specified in the Sonar Begin Analysis build task. I packaged that script up as a custom build task that will read a "sonar.config" file. This means all we have to do is add a "sonar.config" file to each solution we want to run Sonar analysis for, defining the key, name and version for the project, and then this build task will populate all necessary environment variables as the first step in the build.
So not a perfect solution, but it gets the job done without us having to add a lot of extra code to our solutions.

Can I force a plugin in Jenkins to run every single time any job runs

I have a plugin in Jenkins for Checkmarx which scans the source code for static code analysis. Is there to make that plugin be compulsory for every job in jenkins?
For that matter any plugin.
The answer, that you probably don't want to hear, is: No.
The only way you can enforce something to happen at all times, is by writing your own plugin for your own "Project type" (instead of Maven or Free-style), and then enforce that everyone uses your project type.
Found a implicit way to do it.
Using jenkins rest api(batch,python,ruby) - run through all job
config.xml.
Download the jobConfig.xml
Update the xml with the plugin(checkmarx in this case) config
Upload(POST) it back to jenkins server.
Run this on a schedule and it shall force everyone to use it.
As I said its an implicit way of doing it.
Checkmarx plugin provides a build step, so it will run every time the job runs. No need to force, if I understand the question correctly. Just make sure the "Skip scan if triggered by SCM Changes" flag is unchecked, which is the default. See more info about the plugin here: https://checkmarx.atlassian.net/wiki/display/KC/Configuring+a+Scan+Action
Downloading the config.xml for the job and posting it back is a bad idea for several reasons. First checkmarx does not require the code to be compiled so you are wasting precious cycles on a build slave. Second Jenkins jobs can do more than compile and they could deploy to production accidentally. Just don't do it. The best way to do what you want to do is to download the config.xml file and then extract the repository url. You can use the Checkmarx rest api to perform a scan. You can probably name the program in checkmarx in some way to relate it back to the jenkins job.

Resources