跳过正文
Background Image
  1. Posts/

使用 REST API 更新 Jira Server 账号头像

·215 字·1 分钟· ·
沈显鹏
作者
沈显鹏
目录

背景
#

在 CI/CD 中使用 Jira Server 账号(例如 robot)时,如果希望该账号在 Jira 中的头像更专业,但该账号无法登录 Jira GUI,就需要通过 REST API 更新头像。

以下提供 PythonPostman 两种示例。


Python 示例
#

import http.client

conn = http.client.HTTPSConnection("jira.your-company.com")

payload = """{
    "id": "24880",
    "isSelected": false,
    "isSystemAvatar": true,
    "urls": {
        "16x16": "https://jira.your-company.com/secure/useravatar?size=xsmall&avatarId=24880",
        "24x24": "https://jira.your-company.com/secure/useravatar?size=small&avatarId=24880",
        "32x32": "https://jira.your-company.com/secure/useravatar?size=medium&avatarId=24880",
        "48x48": "https://jira.your-company.com/secure/useravatar?avatarId=24880"
    }
}"""

headers = {
    "content-type": "application/json",
    "authorization": "Basic Ymx3bXY6SzhNcnk5ZGI=",  # Base64(username:password)
    "cache-control": "no-cache"
}

conn.request("PUT", "/rest/api/latest/user/avatar?username=robot", payload, headers)
res = conn.getresponse()
print(res.read().decode("utf-8"))

Postman 示例
#

URL & Method

PUT https://jira.your-company.com/rest/api/latest/user/avatar?username=robot

Authorization

  • Type: Basic Auth
  • Username: server-account-username
  • Password: server-account-password

Body

{
  "id": "24880",
  "isSelected": false,
  "isSystemAvatar": true,
  "urls": {
    "16x16": "https://jira.your-company.com/secure/useravatar?size=xsmall&avatarId=24880",
    "24x24": "https://jira.your-company.com/secure/useravatar?size=small&avatarId=24880",
    "32x32": "https://jira.your-company.com/secure/useravatar?size=medium&avatarId=24880",
    "48x48": "https://jira.your-company.com/secure/useravatar?avatarId=24880"
  }
}

如何获取 avatar ID
#

  1. 进入 Jira 个人资料页面。
  2. 在头像选择界面右键查看图片地址。
  3. URL 中的 avatarId 参数即为头像 ID。

示例: https://jira.your-company.com/secure/useravatar?avatarId=24880

find avatar id

相关文章

通过 generic-webhook-trigger 插件实时获取 Bitbucket Repository Events
·716 字·2 分钟
本文介绍如何使用 Jenkins 的 generic-webhook-trigger 插件来实时获取 Bitbucket 仓库的事件信息,如 Pull Request ID 等。
这也能用Jenkins?快速实现一个定期批量登录远程虚拟机并支持添加新的主机名称的Job
·910 字·2 分钟
本文介绍了如何使用 Jenkins 实现定期批量登录远程虚拟机,并支持用户添加新的主机名称,提供了完整的实现代码和步骤。
如何将 Bitbucket 仓库同步到 GitHub
·1218 字·3 分钟
介绍如何通过 Jenkins 将 Bitbucket 仓库的 master 分支同步到 GitHub。
解决 “Remote session was disconnected because there are no Remote Desktop client access licenses available”
·262 字·1 分钟
修复 Windows Server 2012 R2 上的 RDP 连接问题,错误提示为没有可用的远程桌面客户端访问许可证。
Daily Notes
This is only supporting English, not Chinese.
Jenkins 执行 Shell 如果返回值不为0,作业(Job)停止并失败怎么办?
·393 字·1 分钟
如何在 Jenkins Pipeline 中处理 Shell 返回值不为0的情况,以确保作业(Job)在执行成功后仍然显示为成功状态。