Maven - activating profiles based on phase/goal - maven-3

Is it possible to activate profile in Maven based on executed phase or goal?
For example when I execute:
mvn deploy
I want my profile activate.

Related

How to stop a build by buildnumber in a Jenkins pipeline

We uses notes (comments) from Gitlab to issue a couple of user-commands, for example retry a build that seems to have failed from a failed integration etc. We would now like to ask jenkins to stop a build. We have got the buildnumber from the comment (through a callback to to gitlab searching the comments) so we know what build to stop but now we stumbled on the problem. We don't seem to find an api-call to stop the build by buildnumber alone.
We could of course make a request to https://server/project/buildnumber/stop (same url as used by the ui) but then we have to enable the crumbIssuer and according to Ops open for a CSRF-attack.
Is there a way to do this operation from inside a pipeline?
Navigate to Manage Jenkins > Script Console.
Run the following script setting the job name and number of the hung build accordingly:
def build = Jenkins.instance.getItemByFullName("jobName").getBuildByNumber(jobNumber)
build.doStop()
build.doKill()
Otherwise you can create a separate pipeline job and configure the above script
Abort the job build from a cid node (if the previous option did not help):
Log in to any cid node.
Run:
cd /srv/volumes/jenkins/jobs/<job-name>/builds/
rm -rf <hung-build-number>

Jenkins: custom command for any finished build from history with access to this build`s ID, ideally from build history menu

User needs the ability to perform particular action in Jenkins UI on any of the job builds that are already finished with access to the build`s ID.
For each build in history there is menu with items "Changes", "Console output", "Delete build", "Rebuild" etc. Can I add a custom command into that menu using an existing plugin? The command will be "pass build ID to a script on Jenkins machine and launch the script" or at least "put build ID to a file" or "pass build ID to another job and launch it".
Is there any plugin that can do that?
The workarounds I am currently aware of are the following:
a separate Jenkins job that gets required build ID (needs launching another job, correct copying of the build ID)
rename build using menu item "Edit Build Information", then a script/cron job on Jenkins machine will do what it needs to (requires correct renaming)
putting a link to script into html report
artifact an html with the link to script
Looked at the plugins like "batch-task", "sidebar-link" etc., but all work on job level and not on build level.
P.S. It is a free-style Jenkins job, pipeline / Groovy has not been used.
Perhaps a Groovy script might help? How can it look like and how to make launching such script user-friendly (ideally with one button)?

On CircleCI, how can I trigger one build after another, but only if the first is green

I've managed to create a CircleCI build that triggers a subsequent build using their API using curl. I've added this to my circle.yml:
test:
override:
- mvn test -s settings.xml
- mvn deploy -Prun-its -s settings.xml
- curl -v -X POST https://circleci.com/api/v1/project/alexec/docker-maven-plugin/tree/master?circle-token=$CIRCLE_TOKEN
How do I trigger only if all of the previous steps are green?
I think you should do this in the deployment section: Since this is - by definition - only run if everything is fine, this should do the trick.
See their documentation on deployment for details. There it says:
These commands are triggered only after a successful (green) build.
You should have a requires variable in your job that you want to run only if the previous job has run. So you give the requires variable a value of the job name that you want to succeed first before the jobs resume running.
See this example: https://circleci.com/docs/2.0/configuration-reference/

How to trigger a Jenkins job using the p4 plugin or p4?

I've installed this p4 plugin in a Jenkins job. This scynces a workspace to the latest change and then builds. Now, under "Build Triggers", I've chosen "Build periodically" and set the job to run every 10 mins. Is there a way do trigger this Jenkins job when a new submit comes in to P4? Do I use the plugin or do I do something with "p4 trigger"? If so, how can I do this?
Thank you!
Under the same Build Triggers section, there is an option named Poll SCM. Enable that option. This option is present by default when you install Jenkins. It does exactly what you're looking for. It will trigger build as soon as it detects a new commit in P4. Although not necessary, it's good to enable Quiet period too. This option is under Advanced Project Options section (refer snapshot below). Also read Help (?) that's provided with every option to gain better understanding of what it does.
This is how to set up p4 url triggers.
Generate your API key, click your username in the top right > click configure > then generate a new API token!
In your build configuration check the "Trigger builds remotely (e.g., from scripts)", then write whatever you want as the authentication token I wrote "MadeUpToken"
The next step is to run this curl command:
curl -X POST -L --user your-jenkins-username:11170e251c58b2768d4d26bc1db3d6395f https://Your-Jenkins-URL.com/job/Local_UE4/build?token=MadeUpToken

Run Nant script as a Jenkins post build action

Is it possible to run a Nant script as a Jenkins post build action?
I get the option to run a script as a Build Step but not as a build action. Is there any particular plugin which enables this option.
The reason I am looking for this functionality is that I need to run a script which depends on the ArtifactDeployer post build action. If i specify the code in the build step it gets executed before the ArtifactDeployer and the build fails
You can use the Post Build Task Plugin
edit
One way of getting the build number if it's not working with this plugin is using the Groovy Post Build Plugin
With it you can execute groovy code as a post build action, get the build number and execute NAnt
the build number is accessible from the following property
manager.build.number
Post-build Actions -> Execute a set of script run after a build when it succeeds or fails. My experience shows that it only sometimes runs when a build is aborted.
As advised above, the Post-build Actions -> Post build task (via the named post task plug in) is always evaluated for run (regardless of the build exit status). Additional setting via phrase in the log ("Build was aborted") works reliable for me.
My problem was to run something even on an aborted build and post build task sorted out this problem.

Resources