jenkins Extended E-mail Notification: ${BUILD_URL} 's port is wrong - email

I use the Extended E-mail Notification to set the mail notification. The tomcat default port is 8080, but I change to 9080.
I visited jenkins with this URL: http://*.*.*.14:9080/jenkins/configure
Now I set Extended E-mail Notification default content. Here is the code:
build result (For xxx) - "${PROJECT_URL}ws"${PROJECT_URL}
SVN Url "${BUILD_URL}${BUILD_URL}
When I see the mail, the url port is not 9080, but 8080.
http://*.*.*.*:8080/jenkins/job/FinanceSys/70/
Does anyone know why?

Go to Manage Jenkins -> Configure System, locate the "Jenkins Location" section and make sure that the Jenkins URL is setup properly. I believe that value is what the Extended Email Notification plugin uses, not the URL you are using to access Jenkins in the browser.
For example, you could access Jenkins with "localhost:8080", but the emails get generated with "my.company.com:8080" - because that's what the Jenkins URL is set to.

Related

Jenkins Embeddable Build Status plugin gets redirected due to SSO

I'm trying to add Jenkins build status using the Embeddable Build Status plugin onto Github README.md file. I have SSO for Github and Jenkins and I assumed it will have the login info in the browser cookies or wherever it stored that info but looks like it doesn't work that way (The same URL works and picks up SSO info and doesn't prompt me when I open it from a browser. It just doesn't like Github pulling that info)
I see a 302 redirect on the Jenkins status badge link that is getting redirected to the SSO page and is expecting JS to be enabled for it to work which isn't possible on a Github README.md page (Even if that was possible I would not see a login prompt)
The console has a warning for this redirected URL request as Cross-Origin Read Blocking (CORB) blocked cross-origin response <the-URL> with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.
I also set the Jenkins config to ViewStatus for anonymous uses based on JENKINS-17798 and I'm using the unprotected link but it still needs SSO
Is there a way I can fix this?
Read this first. Cors-Filter Plugin for Jenkins.
Before you go debugging. First make sure that CORS is enabled for the Jenkins instance. You can go to configure system in jenkins and then to CORS Filter:
A very short summary.
Access-Control-Allow-Origins - List domains that may access the jenkins url.
Access-Control-Allow-Headers - Headers that can be used to make actual request
Access-Control-Expose-Headers - List of headers browser are allowed to access.
Whenever one tries to go authenticating from one domain to another it usually gets redirected in jenkins if CORS Filter is not active. So try this first.

keycloak configuration http-Link in "verify email"

When my users receive the "Please verifiy email link" the Link in the template is always: http://localhost:8280/auth....
First I tried to set the frontend URL in my realm:
But after this change I cannot start my quarkus-application anymore because I get the following error message: issuer validation error: received [https://myLinkToMyWebsite.com/auth/realms/turniersoftware]
So I removed this setting in keycloak.
I thought that keycloak is using this url for email broadcasts. "Quarkus-portal" is my java-application.
If I click impersonate user in keycloak and set the action "verifiy email" in keycloak admin web, I get the email verifiy email with the correct link.
If my java-program says "sendVerifyEmail" it will send out with "localhost:8280"
Can someone please explain me, what I have to configure to get the domain in my email broadcasts correct. Thank you
As per to the keycloak docs The default hostname provider uses the configured frontendUrl as the base URL for frontend requests (requests from user-agents) and uses the request URL as the basis for backend requests (direct requests from clients).
In your case I think the client configured is a Java client(which is backend) , so in order to force all the backend requests to pass through the public domain(frontendUrl) you might want to set the forceBackendUrlToFrontendUrl property to true in the standalone.xml file.
Please check the below link for further reference.
Hostname SPI

Hubot use github webhook

I am totally new in hubot, and I am stuck at something seems easy.
I want to use this plugin to send messages to users via slack when they have a mention comment or there's a comment on their pull requests.
But I have some trouble setting on Github webhook, how to fill in this form correctly? What's the hubot_url should be? If I test on my local machine, should the URL be http://localhost:port/hubot/github-pull-request?room=ROOM&only-mentioned=1?
And what's the port of hubot if I test it on my local machine? It seems I fill it with wrong data. The delivery failed and got a service timeout error.

How can I set the Sender's address in Jenkins?

I'm sending mail from Jenkins to an anonymous SMTP relay internally. That relay then securely sends mail to exchange online via TLS on port 587. The transport works perfectly, the issue is that Microsoft requires the Sender address match the authentication credentials login name which is the same as the account email address. For example sake, say this is foo#mycompany.com. How can I make jenkins always send mail from foo#mycompany.com?
BTW when I say the transport works perfectly what I mean specifically is that I can drop a formatted e-mail file into the "Pickup" directory on the SMTP relay server and it is properly sent to any recipient provided the From address is foo#mycompany.com.
Jenkins uses the System Admin e-mail address as the sender address for e-mail notification. You can configure this under Manage Jenkins -> Configure System. This is under the Jenkins Location header on that page! It is not immediately obvious that this setting is tied to the e-mail notification settings, since it is not under the E-mail notification header on the configuration page.
Manage Jenkins -> Configure System -> Jenkins Location -> System Admin e-mail address
You can search the page for "Jenkins Location" to change the default value of address not configured yet to whatever you want.
There are two places to add the "E-Mail Notificaitons"
Global level
Local level (Jenkins job level)
To set the E-Mail Notification at Global Level, follow below steps -
1) Go to Manage Jenkins
2) Configure System
3) Jenkins Location
4) System Admin e-mail address
To set the E-Mail Notification at local level (per Jenkins job level), follow below steps -
1) Click on the Job name (if existing one)
2) click on the "Configure"
3) Then look for the "Post-build Action"
4) Specify the email address under "E-mail Notification".
5) Save the changes.
I'm not sure if it is what you meant, but Jenkins enables you to provide a full Sender E-mail Address for notifications. Go to Manage jenkins, then System configuration and find section called E-mail Notification.
You can provide you email address in a form of Jenkins <foo#mycompany.com>.
If you need to do this without using the jenkins UI (for instance in automating a jenkins setup) - you can do so with a groovy script.
import jenkins.model.*
def jenkinsLocationConfiguration = JenkinsLocationConfiguration.get()
jenkinsLocationConfiguration.setAdminAddress("[your admin name] <[your admin email address]>")
// example format -> .setAdminAddress("Jane Doe <foo#company_email.com>")
jenkinsLocationConfiguration.save()
Do note: I did not write this script (although I have tested it and it works), all credit to Peter Halliday and his website with other helpful groovy scripts here.
import javax.mail.Message.RecipientType
import javax.mail.Address
import javax.mail.internet.InternetAddress
import javax.mail.internet.MimeMessage
msg.setFrom(new InternetAddress("john...#server.com"))

Jenkins and GitHub webhook: HTTP 403

I have a GitHub repository which I would like to have notify Jenkins of new commits via a post-receive hook. I've installed the GitHub plugin into Jenkins and have allowed for Jenkins to manage it's own hook URLs. The project has the correct git repository URL and is instructed to "Build when a change is pushed to GitHub". When I have GitHub send a test payload I find this in the nginx webserver that front's Jenkins:
207.97.227.233 - - [15/Sep/2011:07:36:51 +0000] "POST /github-webhook/ HTTP/1.1" 403 561 "-" "-"
I was running SSL so I disabled it to no effect. Do I need to provide special permissions to an anonymous user in the permissions matrix?
Please forgive the lack of configuration files: I'm happy to share those that might exist but I don't know what might be useful to share.
As I don't allow anonymous access, it turns out I needed to create a specific user for GitHub pushes and to grant it Overall read, Job create and Job read. It was also necessary to bundle the authentication into the webhook URL, like so:
https://foo:password#jenkins.example.com/github-webhook/
From Github's instructions ("Configuring global authentication", the first section),
1. Create a user in Jenkins which has, at a minimum, Job/Build permissions
2. Log in as that user (this is required even if you are a Jenkins admin user), then click on the user's name in the top right corner of the page
3. Click 'Configure,' then 'Show API Token...', and note/copy the User ID and API Token.
4. In GitLab, when you create webhooks to trigger Jenkins jobs, use this format for the URL and do not enter anything for 'Secret Token': http://USERID:APITOKEN#JENKINS_URL/project/YOUR_JOB
In my case I used http://USERID:APITOKEN#myIPaddress:808/ and no project/YOUR_JOB
As previously mentioned Jenkins does not allow anonymous access (you don't want people to trigger builds for you!). Adding a username and password in the clear is not the best solution.
1) If your Jenkins is behind a VPN, you need to make sure that your Jenkins webhooks URL are exposed
2) In the GitHub plugin configuration add the correct accessible Jenkins webhook URL(https://jenkins.example.com/github-webhook/) in Override Hook URL
3) Add a secret in the Shared secret section (preferably a long random string). This would be a token sent from Jenkins to GitHub and vice versa for authentication. This should be different from the GitHub Server Credentials!
4) Make sure the user has owner access to add webhooks to your GitHub repos
5) Don't forget to re-register the webhooks after this
https://username:password#jenkins.example.com/github-webhook/ worked for me but the password has to be encoded for the payload to work. My github was not able to contact jenkins due to nginx authorisation but passing username and encoded password worked!