How to set a directory sync to occur at a specific time
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
Jira synchronizes User Directories at a hard coded interval, rather than at a specific time. Some customers may wish to set this sync to a specific time each day, for example, at midnight (see JRASERVER-67963 - Allow to schedule the user directory synchronisation job)
The interval, and next run time of a directory sync can be confirmed by visiting Jira Admin → System → Scheduler details, and find the scheduled task with name com.atlassian.crowd.manager.directory.monitor.poller.DirectoryPollerManager.DIRECTORY_ID
, where DIRECTORY_ID
is the ID of your directory
To determine the directory ID for your specific directory, visit Jira Admin → User Management → User Directories → Directory Configuration Summary
Provided the desired sync outcome is once a day, it is possible to manipulate the next run and sync interval to achieve the desired sync time.
Solution
Choose one of the solutions below
A. Modify the Sync Interval manually:
Visit Jira Admin → User Management → User Directories, and Edit the directory to be changed
Set the Sync Interval to be 30 minutes. This means that the next time the sync happens, the next run time will be set to 30 minutes after the time the sync started.
Wait for the next sync to occur. To check the next run time, visit Jira Admin → System → Scheduler details as described above
Once the next sync starts, change the directory sync interval to a value that will result in the sync occurring at the desired time
Once the next run time is showing as the desired time, modify the directory sync interval to be 1440 (meaning 24 hours)
ℹ️ The next time the sync runs, it will now occur every 24 hours at the time desired
B. Manage the Sync Interval with a Bash script:
The Bash script below runs a directory sync of all enabled directories, be sure to update your credentials. The script and its contents are not supported by Atlassian and are only provided on a best-effort basis. Use at your own risk.
To prevent the auto synchronization task from taking place, configure the Synchronization Interval (in minutes) to a value that is greater than the interval the script will be executed on. For example, if the script is run once a day configure the Synchronization Interval value to 1800 (30 hours in minutes). From that point forward Jira would not reach a point in time when the synchronization is triggered unless the script was not executed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
set -x
# we need the base URL of the app (ie: https://jira.domain.com)
BASEURL=$1
[ -z "$BASEURL" ] && echo "usage: $0 BASEURL" && exit 1
# build the URL needed to grab the xtoken
URL="$BASEURL/plugins/servlet/embedded-crowd/directories/list"
# store the cookie as a temp file that is deleted as we finish
COOKIE=/tmp/GetRest.$$
RESP=/tmp/GetToken.$$
# login and save the cookie
curl -k -c $COOKIE -s -X POST \
--data 'os_username=your_admin_username' --data 'os_password=your_admin_password' --data "formname=loginform" --data "login='Log In'" \
"$BASEURL/dologin.action" -o /dev/null
# get the list of sync opertaions by getting the URL with the cookie
curl -k -b $COOKIE -s -X GET "$URL" > $RESP
# here is an example of the sync operation
# href="/plugins/servlet/embedded-crowd/directories/sync?directoryId=10501&atl_token=d5265f974829752eaa45a94011452b1b05f3f730">
# look for all of the available sync operations and call each one-by-one
for i in `grep /sync $RESP | grep atl_token= | grep -v "{id}" | sed 's/^.*href="//; s/".$//'` ; do
curl -k -b $COOKIE -s -X GET "$BASEURL$i"
done
# delete the temp files
rm -f $COOKIE $TOKEN
JRASERVER-68724 - Trigger Directory Syncs using the REST API includes alternative bash scripts in the comments section. The following example was tested with Jira 8.5.3 and contains the following changes and fixes:
Username and password is parameterized using environment variables
Username and password parameters are url-encoded in curl commands (fixes problems with special characters)
Fixed to cleanup of /tmp/GetToken.* files
Disable "set -x" to prevent output of clear text admin passwords
Example usage:
1
USERNAME=myusername PASSWORD=mypassword ./jira-directory-sync.sh https://jira.domain.com
Contents of file jira-directory-sync.sh:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Source: https://jira.atlassian.com/browse/JRASERVER-68724
#set -x
# USERNAME and PASSWORD are expected to be set as environment variables.
# The base URL of the app is given on the command line (ie: https://jira.domain.com)
BASEURL=$1
[ -z "$BASEURL" ] && echo "usage: USERNAME=myusername PASSWORD=mypassword $0 BASEURL" && exit 1
# Required URLs and paths:
WEB_START_URL="${BASEURL}/login.jsp"
WEB_LOGIN_URL="${BASEURL}/login.jsp"
WEB_SUDO_URL="${BASEURL}/secure/admin/WebSudoAuthenticate.jspa"
WEB_DIRLIST_PATH="/plugins/servlet/embedded-crowd/directories/list"
# store the cookie as a temp file that is deleted as we finish
COOKIE=/tmp/GetRest.$$
RESP=/tmp/GetToken.$$
# Render the login page to get some cookies
curl -k -c $COOKIE -s "${WEB_START_URL}" -o /dev/null
# login and save the cookie
curl -k -b $COOKIE -c $COOKIE -s -X POST \
--data-urlencode "os_username=${USERNAME}" \
--data-urlencode "os_password=${PASSWORD}" \
--data "login='Log In'" \
--data "os_destination=${WEB_DIRLIST_PATH}" \
--data "user_role=SYSADMIN" \
--data "atl_token=" \
"${WEB_LOGIN_URL}" -o /dev/null
# Do web sudo
curl -k -b $COOKIE -c $COOKIE -s -X POST \
--data-urlencode "webSudoPassword=${PASSWORD}" \
--data "webSudoDestination=${WEB_DIRLIST_PATH}" \
--data 'webSudoIsPost=false' \
"${WEB_SUDO_URL}" -o /dev/null
# get the list of sync opertaions by getting the URL with the cookie
curl -k -b $COOKIE -c $COOKIE -s -X GET "${BASEURL}${WEB_DIRLIST_PATH}" > $RESP
# look for all of the available sync operations and call each one-by-one
for sync_path in $(grep /sync $RESP | grep atl_token= | grep -v "{id}" | sed 's/^.*href="//; s/".$//') ; do
curl -k -b $COOKIE -s -X GET "${BASEURL}${sync_path}"
done
# delete the temp files
rm -f $COOKIE $RESP
Was this helpful?