lundi 13 février 2017

JIRA server tips and tricks : WF properties on Status

(note : this works on JIRA Server / Datacenter at the time of the writing of this, Feb 2017)


 Sometimes, you want to set some permissions directly depending on the JIRA Issue Workflow status (i.e. not depending on the whole Permissions scheme applied at the whole project level).

This hard to find trick consist in using Workflow properties on the WF steps.



Use-case : lock the "edit" button on 1 WF step, to 3 user groups

ref :

In order to allow the Edit right only to a specific user group, you need to add the following property to the workflow step impacted  so that only JIRA administrators can edit an issue
jira.permission.edit.group=jira-administrators


To add multiple groups, use the syntax :
jira.permission.edit.group.1=jira-administrators 
jira.permission.edit.group.2=jira-fr
jira.permission.edit.group.3=jira-pmo

 

This of course needs to be applied for each step/status of the workflow impacted, making sure that this WF is not shared with other projects or other IT.


JIRA : Status Permissions


Please note that the expected format is not <property> = denied This format actually grants access to the user named denied.
The proper format is is:
<property>.denied = whatever

The complete format is:

<permission key> = jira.permission[.subtasks].<system project permission>.<grant type>[.<suffix>]
 
<system project permission> =   assign
                                | assignable
                                | attach
                                | attachdeleteall
                                | attachdeleteown
                                | browse
                                | close
                                | comment
                                | commentdeleteall
                                | commentdeleteown
                                | commenteditall
                                | commenteditown
                                | create
                                | delete
                                | edit
                                | link
                                | managewatcherlist
                                | modifyreporter
                                | move
                                | project
                                | resolve
                                | scheduleissue
                                | setsecurity
                                | transition
                                | viewversioncontrol
                                | viewvotersandwatchers
                                | viewworkflowreadonly
                                | work
                                | worklogdeleteall
                                | worklogdeleteown
                                | worklogeditall
                                | worklogeditown
                                        
<grant type> =  denied
                | groupCF
                | assignee
                | assigneeassignable
                | reporter
                | reportercreate
                | userCF
                | applicationRole
                | group 
                | lead
                | projectrole 
                | user
 
<suffix> = any text that makes the permission key unique among all keys of permissions in the same workflow step.


 


lundi 30 janvier 2017

JIRA Script Runner / split cascading field in two text fields

JIRA 7.1.7
Script Runner 4.3.16

import com.atlassian.event.api.EventListener
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Logger
 
def cfNameCascading = "Cascading Field Name";
def cfNameFirst     = "Cascading Field Name : part 1";
def cfNameSecond    = "Cascading Field Name : part 2";
 
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
 
/** Get the different CF objects**/
CustomField cfCascading = customFieldManager.getCustomFieldObjectByName(cfNameCascading)
CustomField cfFirst = customFieldManager.getCustomFieldObjectByName(cfNameFirst)
CustomField cfSecond = customFieldManager.getCustomFieldObjectByName(cfNameSecond)
 
/** Get Cascading Field values (map) **/
Map cfVal = issue.getCustomFieldValue(cfCascading) as Map
if (cfVal) {
    String valFirst = cfVal.get(null);
    String valSecond = cfVal.get("1");
    List allValues = cfVal.values() as List;
 
    log.info("First - second: $valFirst - $valSecond");
    log.info("All: $allValues");
 
    /** Set each separate CF **/
    issue.setCustomFieldValue(cfFirst,  valFirst);
    issue.setCustomFieldValue(cfSecond, valSecond);
 
    /** update the issue **/
    issueManager.updateIssue(event.getUser(), issue, EventDispatchOption.DO_NOT_DISPATCH, false);
} else {
    log.info("Custom field not present on this issue")
}

vendredi 6 janvier 2017

JIRA Server - redirect to full issue view after creation

 (note : this works with most version of JIRA available as of now,  Janvier 2017)

Instead of staying in the current view, you can use the following tricks to make your JIRA SERVER / DATACENTER redirect directly to the recently created issue.


JavaScript (in banner)

The trick here is to disable the "popup" with the create screen, hence going to the "full create screen" which opens the page afterward.

<script type="text/javascript">
AJS.$("#create_link").removeClass("create-issue");
$("#announcement-banner").hide()</script>

cf. : https://confluence.atlassian.com/jirakb/how-to-disable-create-issue-popup-300813780.html

 

Plugin "Issue Quick Start" (and JS source)


The following plugin aims at the same :


Excerpt from the source :

AJS.$(document).on('DOMNodeInserted', function(event) {
    if (event.target.id == 'aui-flag-container') {
        console.log('issue-quick-start: Got post-it note!');
        AJS.$(event.target).on('DOMNodeInserted', function(event) {
            console.log('issue-quick-start: Post-it HTML: ' + event.target.innerHTML);
            var postItLink = AJS.$(event.target.innerHTML).find('a');
            var postItPath = postItLink.attr('href');
            if (postItPath && postItLink.attr('data-issue-key')) {
                console.log('issue-quick-start: Going to new issue path ' + postItPath);
                window.location = postItPath;
            }
        })
    }
});


[TODO] Script Runner : redirect with script fragment (??)

  • Is there some cleaner way to do it with SR "Script Fragments" to perform the redirect ?

cf. https://scriptrunner.adaptavist.com/4.3.7/jira/fragments/WebItem.html#_redirects

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.sal.api.ApplicationProperties
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
 
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
 
@BaseScript CustomEndpointDelegate delegate
 
def labelManager = ComponentAccessor.getComponent(LabelManager)
def applicationProperties = ScriptRunnerImpl.getOsgiService(ApplicationProperties)
def issueManager = ComponentAccessor.getIssueManager()
 
labelIssue(httpMethod: "GET") { MultivaluedMap queryParams ->
 
    def issueId = queryParams.getFirst("issueId") as Long
    def issue = issueManager.getIssueObject(issueId)
 
/**    def label = labelManager.getLabels(issueId)
    if (! label) {
        labelManager.addLabel(null, issueId, "approved", false)
    }
**/
    Response.temporaryRedirect(URI.create("${applicationProperties.baseUrl}/browse/${issue.key}")).build()
}


lundi 4 juillet 2016

Dimming screen / "night mode" for android or mac

Applications I used to dim my screen, reduce the amount of "blue color" that is supposed to make you awake :



mardi 14 juin 2016

MySQL to CSV file



SELECT order_id,product_name,qty
FROM orders
WHERE foo = 'bar'
INTO OUTFILE '/tmp/orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';


TODO : There is still to find how to print the column titles along with the result...




lundi 29 février 2016

VirtualBox install / config de base

 * Config Clavier Mac sous Debian :
https://lokan.fr/2013/12/11/configurer-correctement-son-clavier-mac-sous-debian/
XKBMODEL="pc105"
XKBLAYOUT="fr"
XKBVARIANT="mac"
XKBOPTIONS="lv3:switch,compose:lwin”
* Config redimensionner fenêtre VirtualBox
(non testé ) : https://forums.virtualbox.org/viewtopic.php?f=2&t=68966
* http://download.virtualbox.org/virtualbox/5.0.14/
* http://download.virtualbox.org/virtualbox/5.0.14/UserManual.pdf
* Be sure to have the kernel headers, gcc and other basic build-tools installed
apt-cache search/apt-get install build-essential linux-headers-$(uname -r) dkms

* If present, it should be in /media/cdrom (or /media/cdrom0)
cd /media/cdrom0
sh VBoxLinuxAdditions.run

* NB : you might need to reboot the host.
* You can now add some shared folders (for example). They will be owned by root with drwxrwx--- root vboxsf (group)
* Add user in group vboxsf :
sudo usermod cm -a -G vboxsf


mardi 26 janvier 2016

Monitoring : POC around Monit + M/Monit





Monit + M/Monit
OpenSouce, on bitbucket. https://bitbucket.org/tildeslash/monit/



Monit : "Agent" or "Slave", running on each server where monit his used.
https://mmonit.com/monit/

M/Monit : "Master" allowing to connect, get and coordinate events and actions to&from all monit agents connected.
https://www.mmonit.com/



mmonit manual :
https://mmonit.com/documentation/mmonit_manual.pdf
https://mmonit.com/wiki/Monit/ConfigurationExamples



idea 1 : how to enhance this project : contribute a "log snippet" =
along side with the "start/stop program" in the config file, add a "logfile path" configuration setup that would watch this file(s) and make it available to the agent, and then to the master.

idea 2 : interface monit & elasticsearch (or implement monit within elasticsearch ?)





-----
Other monitoring tools :

* Prometheus "
An open-source service monitoring system and time series database."
http://prometheus.io/docs/introduction/getting_started/
 https://github.com/prometheus/prometheus


 * Sensu : A monitoring framework that aims to be simple, malleable, and scalable
https://sensuapp.org/
https://github.com/sensu/sensu

 * Ganglia
 http://ganglia.info/

lundi 26 octobre 2015

Scripting : set variables depending how the where launched (terminal mode, cron/auto mode, ...)

You all know the deal : when you launch a command it (obviously) comes with all your environment variables. But when you want to cron it, none of them is present. We hence want to set some variables, but only in some cases. The "tty" command will help us do so.


You can use the tty tool to check if a script is called from the standard output :


if ! tty -s
then
    exec >/dev/null 2>&1
else
    MAIL_DEST="email@server.ext"
fi



  • The command tty returns :

User Commands                                              tty(1)

NAME
     tty - return user's terminal name

SYNOPSIS
     tty [-l] [-s]

DESCRIPTION
     The tty utility writes to the standard output  the  name  of
     the  terminal  that is open as standard input. The name that
     is used is equivalent to the string that would  be  returned
     by the ttyname(3C) function.

OPTIONS
     The following options are supported:

     -l       Prints the synchronous line  number  to  which  the
              user's terminal is connected, if it is on an active
              synchronous line.

     -s       Inhibits printing of the terminal path name, allow-
              ing one to test just the exit status.

EXIT STATUS
     The following exit values are returned:

     0        Standard input is a terminal.

     1        Standard input is not a terminal.

     >1       An error occurred.

 

lundi 19 octobre 2015

MS Word shortcuts

Sometimes you're bound to use it for professional purposes...



3 shortcuts on MS-Word :

  • Shift + F3 : change the current word type case between ALLUPPER <-> alllower <-> Firstcharup.
  • Shift + F4 / F5 : navigate 1 screen forward (f4) / backward (f5.

  • Control + Y : repeat the last action performed.