Skip to content

Commit b7c3a3b

Browse files
[patch] add pipeline name in message
1 parent 9527f56 commit b7c3a3b

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

bin/mas-devops-notify-slack

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def notifyProvisionRoks(channels: list[str], rc: int, additionalMsg: str | None
9797
return response.data.get("ok", False)
9898

9999

100-
def notifyPipelineStart(channels: list[str], instanceId: str | None = None) -> dict | None:
100+
def notifyPipelineStart(channels: list[str], instanceId: str | None = None, pipelineName: str | None = None) -> dict | None:
101101
"""Send Slack notification about pipeline start and create thread."""
102102
namespace = f"mas-{instanceId}-pipelines"
103103
if instanceId is None or instanceId == "":
@@ -114,7 +114,7 @@ def notifyPipelineStart(channels: list[str], instanceId: str | None = None) -> d
114114
toolchainLink = _getToolchainLink()
115115
instanceInfo = f"\nInstance ID: `{instanceId}`" if instanceId else ""
116116
message = [
117-
SlackUtil.buildHeader("🚀 MAS Pipeline Started"),
117+
SlackUtil.buildHeader(f"🚀 MAS {pipelineName} Pipeline Started"),
118118
SlackUtil.buildSection(f"Pipeline Run: {instanceInfo}\n{toolchainLink}")
119119
]
120120
response = SlackUtil.postMessageBlocks(channels[0], message)
@@ -129,7 +129,7 @@ def notifyPipelineStart(channels: list[str], instanceId: str | None = None) -> d
129129
return False
130130

131131

132-
def notifyAnsibleStart(channels: list[str], taskName: str, instanceId: str | None = None) -> bool:
132+
def notifyAnsibleStart(channels: list[str], taskName: str, instanceId: str | None = None, pipelineName: str | None = None) -> bool:
133133
"""Send Slack notification about Ansible task start."""
134134
namespace = f"mas-{instanceId}-pipelines"
135135
if instanceId is None or instanceId == "":
@@ -140,7 +140,7 @@ def notifyAnsibleStart(channels: list[str], taskName: str, instanceId: str | Non
140140
threadInfo = SlackUtil.getThreadConfigMap(namespace, instanceId)
141141
if threadInfo is None:
142142
print("No thread found - creating pipeline start notification")
143-
notifyPipelineStart(channels, instanceId)
143+
threadInfo = notifyPipelineStart(channels, instanceId, pipelineName)
144144
threadId = threadInfo.get("threadId")
145145
channelId = threadInfo.get("channelId")
146146

@@ -154,7 +154,7 @@ def notifyAnsibleStart(channels: list[str], taskName: str, instanceId: str | Non
154154
return response.data.get("ok", False)
155155

156156

157-
def notifyAnsibleComplete(channels: list[str], rc: int, taskName: str, instanceId: str | None = None) -> bool:
157+
def notifyAnsibleComplete(channels: list[str], rc: int, taskName: str, instanceId: str | None = None, pipelineName: str | None = None) -> bool:
158158
"""Send Slack notification about Ansible task completion status."""
159159
namespace = f"mas-{instanceId}-pipelines"
160160
if instanceId is None or instanceId == "":
@@ -165,7 +165,7 @@ def notifyAnsibleComplete(channels: list[str], rc: int, taskName: str, instanceI
165165
threadInfo = SlackUtil.getThreadConfigMap(namespace, instanceId)
166166
if threadInfo is None:
167167
print("No thread found - creating pipeline start notification")
168-
notifyPipelineStart(channels, instanceId)
168+
threadInfo = notifyPipelineStart(channels, instanceId, pipelineName)
169169
# Send task completion message as thread reply
170170
threadId = threadInfo.get("threadId")
171171
channelId = threadInfo.get("channelId")
@@ -186,7 +186,7 @@ def notifyAnsibleComplete(channels: list[str], rc: int, taskName: str, instanceI
186186
return response.data.get("ok", False)
187187

188188

189-
def notifyPipelineComplete(channels: list[str], rc: int, instanceId: str | None = None) -> bool:
189+
def notifyPipelineComplete(channels: list[str], rc: int, instanceId: str | None = None, pipelineName: str | None = None) -> bool:
190190
"""Send Slack notification about pipeline completion and cleanup ConfigMap."""
191191
namespace = f"mas-{instanceId}-pipelines"
192192
if instanceId is None or instanceId == "":
@@ -226,7 +226,7 @@ def notifyPipelineComplete(channels: list[str], rc: int, instanceId: str | None
226226
status = "Failed"
227227
additionalInfo = f"\nPipeline failed with return code: `{rc}`"
228228
message = [
229-
SlackUtil.buildHeader(f"{emoji} MAS Pipeline {status}"),
229+
SlackUtil.buildHeader(f"{emoji} MAS {pipelineName} Pipeline {status}"),
230230
SlackUtil.buildSection(f"Pipeline Run: {instanceInfo}{durationText}{additionalInfo}")
231231
]
232232
response = SlackUtil.postMessageBlocks(channelId, message, threadId)
@@ -252,10 +252,11 @@ if __name__ == "__main__":
252252

253253
# Primary Options
254254
parser.add_argument("--action", required=True)
255-
parser.add_argument("--rc", required=True, type=int)
255+
parser.add_argument("--rc", required=False, type=int)
256256
parser.add_argument("--msg", required=False, default=None)
257257
parser.add_argument("--task-name", required=False, default="")
258258
parser.add_argument("--instance-id", required=False, default=None)
259+
parser.add_argument("--pipeline-name", required=False, default=None)
259260

260261
args, unknown = parser.parse_known_args()
261262

0 commit comments

Comments
 (0)