How to set a directory sync to occur at a specific time

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。

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.

*Fisheye および Crucible は除く

目的

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 - Getting issue details... STATUS )

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.

ソリューション

Choose one of the solutions below

A. Modify the Sync Interval manually: 

  1. Visit Jira Admin → User Management → User Directories, and Edit the directory to be changed
  2. 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.
  3. Wait for the next sync to occur. To check the next run time, visit Jira Admin → System → Scheduler details as described above
  4. Once the next sync starts, change the directory sync interval to a value that will result in the sync occurring at the desired time
  5. Once the next run time is showing as the desired time, modify the directory sync interval to be 1400 (meaning 24 hours)

(info) 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.

#!/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 - Getting issue details... STATUS  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

使用例


USERNAME=myusername PASSWORD=mypassword ./jira-directory-sync.sh https://jira.domain.com


Contents of file jira-directory-sync.sh:

#!/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



説明 How to set a directory sync to occur at a specific time
製品Jira

最終更新日: 2022 年 2 月 6 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.