Compare commits
No commits in common. "cloud" and "main" have entirely different histories.
1 changed files with 18 additions and 33 deletions
|
@ -1,48 +1,33 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
jira_base_url="https://jira.someserver.com"
|
||||||
|
username="usernName"
|
||||||
|
password="passWord !@#"
|
||||||
|
|
||||||
# Jira Cloud base URL (replace <your-domain> with your actual site)
|
|
||||||
jira_base_url="https://<your-domain>.atlassian.net"
|
|
||||||
|
|
||||||
# Jira Cloud credentials: email + API token
|
|
||||||
username="email@example.com"
|
|
||||||
api_token="YOUR_API_TOKEN"
|
|
||||||
|
|
||||||
# The CSV file containing project key, component name, and user account ID
|
|
||||||
csv_file="components.csv"
|
csv_file="components.csv"
|
||||||
|
|
||||||
|
|
||||||
# Read the CSV file line by line
|
# Read the CSV file line by line
|
||||||
# Format: projectKey|componentName|accountID
|
|
||||||
while IFS='|' read -r project_key component_name user_id; do
|
while IFS='|' read -r project_key component_name user_id; do
|
||||||
# Remove any carriage return characters from the component_name
|
# Remove carriage return characters from the component_name
|
||||||
component_name=$(echo "$component_name" | tr -d '\r')
|
component_name=$(echo "$component_name" | tr -d '\r')
|
||||||
|
|
||||||
# 1. Get the list of components for the project
|
# Get the component ID from Jira API using project_key and component_name
|
||||||
raw_data=$(curl -s -X GET \
|
raw_data=$(curl -s -X GET \
|
||||||
-u "$username:$api_token" \
|
-u "$username:$password" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
"$jira_base_url/rest/api/3/project/$project_key/components")
|
"$jira_base_url/rest/api/2/project/$project_key/components")
|
||||||
|
component_id=$(echo "$raw_data" | jq -r --arg component_name "$component_name" '.[] | select(.name == $component_name) | .id')
|
||||||
|
|
||||||
# 2. Extract the component ID by matching the component name
|
echo "Updating project $project_key, component $component_name with new lead $user_id..."
|
||||||
component_id=$(echo "$raw_data" \
|
|
||||||
| jq -r --arg component_name "$component_name" \
|
|
||||||
'.[] | select(.name == $component_name) | .id')
|
|
||||||
|
|
||||||
if [ -z "$component_id" ]; then
|
# Update the component lead using the component ID and user ID
|
||||||
echo "Error: Could not find component '$component_name' in project '$project_key'."
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Updating project '$project_key', component '$component_name' with new lead '$user_id'..."
|
|
||||||
|
|
||||||
# 3. Update the component lead
|
|
||||||
# Note: On Jira Cloud, you'll generally need the user's accountId in the field `leadAccountId`.
|
|
||||||
curl -s -X PUT \
|
curl -s -X PUT \
|
||||||
-u "$username:$api_token" \
|
-u "$username:$password" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"leadAccountId\":\"$user_id\", \"assigneeType\": \"COMPONENT_LEAD\"}" \
|
-d "{\"leadUserName\":\"$user_id\", \"assigneeType\": \"COMPONENT_LEAD\"}" \
|
||||||
"$jira_base_url/rest/api/3/component/$component_id" > /dev/null
|
"$jira_base_url/rest/api/2/component/$component_id" > /dev/null
|
||||||
|
|
||||||
# 4. Log the update
|
# Output the updated information with a timestamp
|
||||||
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
echo "Updated project '$project_key', component '$component_name' with new lead '$user_id' at $timestamp"
|
echo "Updated project $project_key, component $component_name with new lead $user_id at $timestamp"
|
||||||
done < "$csv_file"
|
done < "$csv_file"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue