Invoking bamboo plan remotely - bamboo

I know it is possible to take down a bamboo artifact remotely, I was wondering is it possible to take start a bamboo from a remote box by sending an appropriate HTTP request?
Thanks,.

Here is an example:
curl --user un:pwd -X POST -d "stage&executeAllStages" -d "bamboo.variable.TEST=WORKS" http://10.0.0.0/rest/api/latest/queue/CAP-BR.json
As you can see I am also passing an optional value to Bamboo bamboo.variable.TEST=WORKS

If I understood your question right, then what you want to do is to trigger a build via the rest api of bamboo.
This could offer you some help:
https://answers.atlassian.com/questions/65517/trigger-bamboo-plan-via-rest-call

Related

How to send notification to Telegram from GitLab pipeline?

In our small startup we use GitLab for development and Telegram for internal communication between developers and PO. Since the PO would like to see the progress immediately, we have set up the GitLab Pipeline so that the preview version is deployed on the web server after each commit. Now we want to expand the pipeline. So that after the deployment a notification is sent via the Telegram group.
So the question - is that possible, and if so, how?
EDIT: since I've already implemented that, that's not a real question. I wanted to post the answer here so that others can use it as well.
So, we'll go through it step by step:
Create a Telegram bot
Add bot to Telegram group
Find out Telegram group Id
Send message via GitLab Pipeline
1. Create a Telegram bot
There are enough good instruction from Telegram itself for this:
https://core.telegram.org/bots#6-botfather
The instructions do not say anything explicitly, but to generate it, you have to go into the chat with the BotFather.
At the end you get a bot token, something like 110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw
2. Add bot to Telegram group
Switch to the Telegram group, and add the created bot as a member (look for the bot by name).
3. Find out Telegram group Id
Get the update status for the bot in browser:
https://api.telegram.org/bot<YourBOTToken>/getUpdates
Find the chat-id in the response:
... "chat": {"id": <YourGroupID>, ...
see for more details: Telegram Bot - how to get a group chat id?
4. Send message via GitLab Pipeline
Send message with a curl command. For example, an existing stage in gitlab pipeline can be extended for this purpose:
upload:
stage: deploy
image: alpine:latest
script:
- 'apk --no-cache add curl'
- 'curl -X POST -H "Content-Type: application/json" -d "{\"chat_id\": \"<YourGroupID>\", \"text\": \"CI: new version was uploaded, see: https://preview.startup.com\"}" https://api.telegram.org/bot<YourBOTToken>/sendMessage '
only:
- main
Remember to adapt the YourBOTToken and YourGroupID, and the text for the message.
*) we use the alpine docker image here, so curl has to be installed - 'apk --no-cache add curl'. With other images this may have to be done in a different way.
One easy way to send notifications (particularly if you're using multiple services or chats) is to use apprise.
To send to one telegram channel:
apprise -vv --body="Notify telegram chat" \
tgram://bottoken/ChatID1 \
This makes it easy to notify many services from your pipeline all at once without needing to write code against the API of each service (apprise handles this for you).
image: python:3.9-slim # or :3.9-alpine if you prefer a smaller image
before_script:
- pip install apprise # consider caching PIP_CACHE_DIR for performance
script: |
# Set a notification to multiple telegram chats, a yahoo email account,
# Slack, and a Kodi Server with a bit of added verbosity:
apprise -vv --body="Notify more than one service" \
tgram://bottoken/ChatID1/ChatID2/ChatIDN \
mailto://user:password#yahoo.com \
slack://token_a/token_b/token_c \
kodi://example.com

Automatically add tasks to new Btibucket Pull request

We have several default tasks that we would like to add to every new pull request in Bitbucket. Since tasks are not supported by the Bitbucket API, the best thing I can think of is to automate it through a Selenium script, or other GUI tester. I'm thinking about kicking it off using a Jenkins job that watches for new pull requests. Can anyone think of a better way to do this?
I found that the tasks endpoint is not documented but is however active.
You can do the following
export PROJECT=yourProject
export REPO=yourRepo
export PR_ID=pullRequestId
export TASK_NAME=theNameOfTheTask
curl -H "Content-Type:application/json" -X POST --user "${TB_USER}:${TB_PASSWORD}" -d '{"content":{"raw":"${TASK_NAME}"}}' "https://api.bitbucket.org/2.0/repositories/${PROJECT}/${REPO}/pullrequests/${PR_ID}/tasks/"
You can also send a GET to get ALL tasks and their status
Thanks for the find!
Quick note, Bitbucket stopped supporting basic auth using your standard user/pass, you'll need to setup an AppPassword and use your normal Bitbucket username (no email).
https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/
Ex:
export PROJECT=yourProject
export REPO=yourRepo
export PR_ID=pullRequestId
export TASK_NAME=theNameOfTheTask
curl -H "Content-Type:application/json" -X POST --user "bt-username:bt-apppassword" -d "{\"content\":{\"raw\":\"${TASK_NAME}\"}}" "https://api.bitbucket.org/2.0/repositories/${PROJECT}/${REPO}/pullrequests/${PR_ID}/tasks/"

Thruk cgi authentication override

I have the latest version of thruk installed with naemon and livestatus. I want to be able to post commands from a python script to cmd.cgi from the same server without the interference of authentication. I have tried the settings of:
use_authentication=0
default_user_name=thrukadmin
but it doesn't seem to work in the thruk gui. When trying to post to the cgi from the thruk gui I get the error, "I'm sorry Dave......"
Any thoughts on why this not working right? The apache server on that system uses ldap to authenticate to the gui, could this be an issue?
Other thoughts?
It's much easier, you don't even need Thruk in the middle. You can simply write to Naemons command_file.
The external command list at https://www.naemon.org/documentation/developer/externalcommands/ contains an example for every possible command.
Here is a shell snippet which schedules a host downtime:
printf "[%lu] SCHEDULE_HOST_DOWNTIME;host1;1478648441;1478638441;1;0;3600;naemonadmin;This is an example comment.\n" `date +%s` > /var/lib/naemon/naemon.cmd
When using Thruk, you can use thruks cli script to send commands:
thruk r -d comment_data=test /hosts/localhost/cmd/schedule_host_downtime
Authentication is only required if you want to send commands by HTTP.

Azure Container Instances stuck in "Creating" state

Whether I have the azure agent plugin for Jenkins make my container, or if I do it manually, it seems like either way it never enters a running state.
az container create \
--os-type Windows \
--location eastus \
--registry-login-server SERVER.azurecr.io \
--registry-password PASSWORD \
--registry-username USERNAME \
--image namespace/image \
--name jenkins-permanent \
--resource-group devops-aci \
--cpu 2 \
--memory 3.5 \
--restart-policy Always \
--command-line "-jnlpUrl http://host:8080/computer/NAME/slave-agent.jnlp -secret SECRET -workDir \"C:\\jenkins\""
I've gone through all the troubleshooting steps that apply, tried a different region, but to no avail.
Here's a current event that I got which seems to be the most progress I've had yet:
{
"count": 1,
"firstTimestamp": "2017-12-07T03:02:56+00:00",
"lastTimestamp": "2017-12-07T03:02:56+00:00",
"message": "Failed to pull image \"MYREPO.azurecr.io/my-company/windows-agent:latest\": Error response from da
emon: {\"message\":\"Get https://MYREPO.azurecr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout
exceeded while awaiting headers)\"}",
"name": "Failed",
"type": "Warning"
}
The funny thing is, this event happens before and after one case of the instance working (but unfortunately my entrypoint command was wrong, so it never started).
I really feel like Azure is punting on this and I just have no way to change the order I do anything. It's simply one command.
Alexander, here's a lead to actually check what could be causing the delay, or if the deployment has failed in the background, this information would be critical to narrow down what the issue is: https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-troubleshoot-tips#determine-error-code
From the article above check on deployment logs:
Enable debug logging:
PowerShell
In PowerShell, set the DeploymentDebugLogLevel parameter to All, ResponseContent, or RequestContent.
New-AzureRmResourceGroupDeployment -ResourceGroupName examplegroup -TemplateFile c:\Azure\Templates\storage.json -DeploymentDebugLogLevel All
or Azure CLI:
az group deployment operation list --resource-group ExampleGroup --name vmlinux
Check Also Check deployment sequence:
Many deployment errors happen when resources are deployed in an unexpected sequence. These errors arise when dependencies are not correctly set. When you are missing a needed dependency, one resource attempts to use a value for another resource but the other does not yet exist.
The above link contains more details. Let me know if this helps.
Figured it out, turns out the backslashes in the command in my executable path were not having their escapes honoured. Either because I was calling az from bash, or because something Azure side isn't handling the escaping correctly, or not escaping them itself.
My solution has been to just use forward slashes in the paths. Windows seems to be handling them correctly, and I prefer to not be bothered with its odd preference for backslashes.
Related to my issue is that the speed of the service makes troubleshooting very difficult. It takes a long time to go round trip with any fixes. So if you're using Azure Container Instances and want better performance, go upvote this feedback item that I've created.
How big is your image? You can always debug with 2 steps.
Run az container show -g devops-aci -n jenkins-permanent. It should contain a list of container events in the container json object. The event message should give you hint what's going on.
Run az container logs -g devops-aci -n jenkins-permanent. It should give you the logs of your container. If it's a problem within your image, you should be able to see some error output.

API support for manual approval of promoted builds in Jenkins?

Is there any way to programmatically approve the Jenkins promoted build?
In job configuration it has been set to "Only when manually approved".
Yes! Although I haven't found any documentation for it and so it might not be a stable solution. I found this using the browser developer tools. Make sure "Only when manually approved" is checked.
Here's an example:
curl 'https://jenkins/job/z-promotion-test/3/promotion/promotionProcess/promotion_test/promotionCondition/hudson.plugins.promoted_builds.conditions.ManualCondition/approve' --data 'json=%7B%7D&Submit=Approve'
Authenticated version
curl 'http://<user>:<token>#jenkins/job/z-promotion-test/3/promotion/promotionProcess/promotion_test/promotionCondition/hudson.plugins.promoted_builds.conditions.ManualCondition/approve' --data 'json=%7B%7D&Submit=Approve'
See
http://jenkins/me/configure
https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API
I too got into the same situation. There is no documentation/help found nowhere. But after some serious plug n play below command made it work. Hope it helps. Please refer below URL
API (curl)Command to Approve a promoted build Job in Jenkins
I know it is almost 2 years since the post published, but thought it could help some others with the same issue. Thanks