LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Friday, May 25, 2018

JIRA APIでカスタムフィールドの値を更新する


JIRAのAPIで特定のカスタムフィールドの値を変更したくて書いたコードです。



コード.gs
function get_jira_token() {
  var id = "LOGIN_EMAIL";
  var pw = "LOGIN_PASSWORD";
  var token = Utilities.base64Encode(id + ":" + pw);
  return token;
}

function get_base_url() {
  var base_url = "https://SITENAME.atlassian.net/rest/api/2/issue/";
  return base_url;
}

function update() {
  var token = get_jira_token();
  var payload = get_payload();
  var options = get_options(token, payload);
  var url = get_url();
  UrlFetchApp.fetch(url, options);
}

function get_url(){
  var key = "KEY-1";
  var url = get_base_url() + key;
  return url;
}

function get_payload(values) {
  var email = Session.getActiveUser().getEmail();
  var data = {
    customfield_10025: "対象のカスタムフィールドに入れる値"
  };
  var fields = {fields: data};
  var payload = JSON.stringify(fields);
  return payload;
}

function get_options(token, payload) {
  var options = {
    method: "PUT",
    payload: payload,
    contentType: "application/json",
    headers: {"Authorization": " Basic " + token}
  }
  return options;
}



上記コード内の以下の値を設定してから

  • LOGIN_EMAIL
  • LOGIN_PASSWORD
  • SITENAME

update() を実行すると以下のようにカスタムフィールドの値が更新できる



参考

JIRA REST API examples
https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/

Latest post

Extracting data from Google Sheets with regular expressions

Introduction Regular expressions are a powerful tool that can be used to extract data from text.  In Google Sheets, regular expressions ca...