Skip to content

Commit d60b98a

Browse files
authored
Merge branch 'master' into feature/seed-improvements
2 parents 3f4defc + de67d04 commit d60b98a

File tree

3 files changed

+171
-170
lines changed

3 files changed

+171
-170
lines changed

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,24 @@ The directory structure is dictated by [OpenShift Jenkins S2I image](https://doc
1818

1919
To Integrate with slack follow the steps at https://github.com/jenkinsci/slack-plugin. Particularly, create a webhook at https://customteamname.slack.com/services/new/jenkins-ci. After the webhook setup is complete at slack, record and add the below environmental variables. You can retrieve the values on your [slack dashboard](https://my.slack.com/services/new/jenkins-ci). Make sure you are logged into the correct team.
2020
1. The base url as `SLACK_BASE_URL`
21-
2. The slack token as `SLACK_TOKEN`
22-
3. The slack room you selected as the default slack channel as `SLACK_ROOM`
23-
4. optionally, a jenkins credential can be used for the token and referenced by a custom id at `SLACK_TOKEN_CREDENTIAL_ID`. This takes precedences over the `SLACK_TOKEN`
21+
2. The slack room you selected as the default slack channel as `SLACK_ROOM`
22+
3. A jenkins credential needs to be created. Use the id of the credential for the environmental variable `SLACK_TOKEN_CREDENTIAL_ID`. When creating this credential in OpenShift, create a secret that syncs withe jenkins and uses the key secrettext. The namespace will automatically be prepended to the credential name. For example, if you create a secret named `slack-token` in the namespace `jenkins` then this variable would be `slack-token` and jenkins will look for the sync'd credential `jenkins-slack-token`.
23+
4. Optionally, you can add your slack team name with the variable `SLACK_TEAM`
24+
25+
Here is an example of the slack token credential secret created in OpenShift
26+
27+
```
28+
kind: Secret
29+
type: Opaque
30+
metadata:
31+
labels:
32+
credential.sync.jenkins.openshift.io: 'true'
33+
build: "jenkins"
34+
app: "jenkins"
35+
name: "slack-token"
36+
stringData:
37+
secrettext: "super-secret-token"
38+
```
2439

2540
## SonarQube Integration
2641

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import jenkins.model.Jenkins
2-
import net.sf.json.JSONObject
3-
42
import java.util.logging.Level
53
import java.util.logging.Logger
64

@@ -10,35 +8,20 @@ final def LOG = Logger.getLogger("LABS")
108
if(slackBaseUrl != null) {
119

1210
LOG.log(Level.INFO, 'Configuring slack...' )
13-
14-
def slackToken = System.getenv('SLACK_TOKEN')
11+
1512
def slackRoom = System.getenv('SLACK_ROOM')
16-
def slackSendAs = ''
17-
def slackTeamDomain = ''
13+
def slackTeamDomain = System.getenv('SLACK_TEAM')
1814
def slackTokenCredentialId = System.getenv('SLACK_TOKEN_CREDENTIAL_ID')
1915

20-
if(slackTokenCredentialId == null) {
21-
slackTokenCredentialId = ''
22-
}
23-
24-
JSONObject formData = ['slack': ['tokenCredentialId': slackTokenCredentialId]] as JSONObject
25-
26-
def slack = Jenkins.instance.getExtensionList(
27-
jenkins.plugins.slack.SlackNotifier.DescriptorImpl.class
28-
)[0]
29-
def params = [
30-
slackBaseUrl: slackBaseUrl,
31-
slackTeamDomain: slackTeamDomain,
32-
slackToken: slackToken,
33-
slackRoom: slackRoom,
34-
slackSendAs: slackSendAs
35-
]
36-
def req = [
37-
getParameter: { name -> params[name] }
38-
] as org.kohsuke.stapler.StaplerRequest
39-
slack.configure(req, formData)
16+
def slack = Jenkins.instance.getDescriptorByType(jenkins.plugins.slack.SlackNotifier.DescriptorImpl)
17+
18+
slack.baseUrl = slackBaseUrl
19+
slack.teamDomain = slackTeamDomain ?: ''
20+
slack.tokenCredentialId = slackTokenCredentialId ? System.getenv('OPENSHIFT_BUILD_NAMESPACE') + "-" + slackTokenCredentialId : ''
21+
slack.room = slackRoom ?: '#jenkins'
22+
slack.save()
4023

4124
LOG.log(Level.INFO, 'Configured slack' )
4225

43-
slack.save()
44-
}
26+
}
27+

0 commit comments

Comments
 (0)