go-jira / jira

simple jira command line client in Go
Apache License 2.0
2.67k stars 326 forks source link

How to create tasks for boards with custom fields? #479

Open kostyay opened 1 year ago

kostyay commented 1 year ago

Hi I'm trying to create a new task using a cli running jira create -i Task, the response that I get doesn't contain any custom fields (im sending it to an editor). When I try to save I get an error saying that a custom field was not provided: ERROR customfield_10059: Team is required.

I tried adding it to the config.yml file like this: customfield_10059: My Team but it didn't do anything. How can I inject custom fields?

kostyay commented 1 year ago

here is an answer for anyone who wishes to do it in the future:

go-jira has a predefined template for the create operation. this template does not contain your custom fields. in order to support new fields you need to edit the template. templates are not present by default, you need to create a file in ~/.jira.d/templates/create and paste the modified template there. you can find the templates in the templates.go file. in my case this was the solution

{{/* create template */ -}}
fields:
  project:
    key: {{ or .overrides.project "" }}
  issuetype:
    name: {{ or .overrides.issuetype "" }}
  summary: >-
    {{ or .overrides.summary "" }}
{{- if .meta.fields.priority.allowedValues}}
  priority: # Values: {{ range .meta.fields.priority.allowedValues }}{{.name}}, {{end}}
    name: {{ or .overrides.priority ""}}
{{- end}}
{{- if .meta.fields.components.allowedValues}}
  components: # Values: {{ range .meta.fields.components.allowedValues }}{{.name}}, {{end}}
  {{ range split "," (or .overrides.components "")}}
    - name: {{ . }}
  {{end}}
{{- end}}
  description: |~
    {{ or .overrides.description "" | indent 4 }}
{{- if .meta.fields.assignee}}
  assignee:
    emailAddress: {{ or .overrides.assignee "" }}
{{end -}}
{{- if .meta.fields.reporter}}
  reporter:
    emailAddress: {{ or .overrides.reporter .overrides.login }}
{{end}}
{{- if .meta.fields.customfield_10110}}
  # watchers
  customfield_10110:
  {{ range split "," (or .overrides.watchers "")}}
    - name: {{.}}
  {{end}}
    - name:
{{- end}}
{{- if .meta.fields.customfield_10059}}
  # team
  customfield_10059:  # Values: {{ range .meta.fields.customfield_10059.allowedValues }}{{.value}}, {{end}}
    value: {{ (or .overrides.team "") }}
{{- end}}