I am attempting to manage our organizations flow of scripts by using GitLab commits to add new scripts through the JAMF API. I am using Jenkins to auto-run these jobs on commit to check for changes, and then post those changes to our organizations JAMF Pro scripts.
I am new with APIs, and am having a hard time figuring out how to post multiple scripts to JAMF using the POST /v1/scripts.
Has anyone ever found a good solution to adding multiple scripts at the same time through the API? And if so, is there a way to avoid this type of parameter declaration? I am still figuring out the SCM pull, so please ignore that part. I just need to know if there is a better way to POST new scripts, and clobber the old ones when scripts are edited.
stages {
stage('Build') {
when { changeset SCM }
steps {
container('ubuntu') {
sh """
username="user"
password="password"
credentials=$(printf "$username:$password" | /usr/bin/iconv -t ISO-8859-1 | /usr/bin/base64 -i - )
jps="https://<jamf_server_url>"
# Create auth token
uapi_token=$(curl -s -H "Content-Type: application/json" -H "Authorization: Basic ${credentials}" -X POST "${jps}/uapi/auth/tokens" | jq -r '.token')
curl -X POST "<jamf_server_url>" \\
-H "accept: application/json" \\
-H "Authorization: Bearer ${uapi_token}"
-d "{\\"name\\":\\"Install Developer Utils Script\\",\\"info\\":\\"Installs utilities for developers\\",\\"notes\\":\\"Should be able to be re-run without problem.\\", "priority\\":\\"AFTER\\",\\"categoryId\\":\\"1\\",\\"categoryName\\":\\"Developer Tools\\",\\"parameter4\\":\\"1\\",\\"parameter5\\":\\"2\\",\\"parameter6\\":\\"3\\", \\"parameter7\\":\\"4\\",\\"parameter8\\":\\"5\\",\\"parameter9\\":\\"6\\",\\"parameter10\\":\\"7\\",\\"parameter11\\":\\"8\\",\\"osRequirements\\": \\"10.10.x\\","scriptContents\\":\\"echo \\\\\\"Trivial script.\\\\\\"\\"}"
"""
}
}
}
}