Creating a script asset with CPDCTL
Learn to create a script asset with Cloud Pak for Data command line interface (CPDCTL).
-
Install the CPDCTL library.
CPDCTL_VERSION = "" ! curl -L https://github.com/IBM/cpdctl/releases/download/{CPDCTL_VERSION}/cpdctl_linux_amd64.tar.gz --output cpdctl_linux_amd64.tar.gzCheck for the available Cloud Pak for Data versions in our GitHub releases.
-
Extract downloaded archive.
! tar xzf cpdctl_linux_amd64.tar.gz - Ensure that the
cpdctlarchive is in the current working directory and the system PATH.%%capture %env PATH={CWD}:{PATH} - Check that CLI is accessible.
! cpdctl version -
Optional: The following steps are not required if you are running the script in a Cloud Pak for Data environment runtime.
URL = "<<your cluster URL>>" USERNAME = "<<CPD user name>>" APIKEY = "<<CPD user API key>>" ! cpdctl config context cpd-demo --url {URL} --username {USERNAME} --apikey {APIKEY} project_id = os.getenv('PROJECT_ID') - Open your script.
with open('<test_script>', 'w') as f: f.write("echo OK") - Create the new script asset.
When you run this line of code, you receive the asset ID in its output.! cpdctl asset script create --file <test_script> --project-id {project_id} - List the script asset in the project.
! cpdctl asset search --type-name script --query 'test.sh' --project-id {project_id} -
Optional: You can delete the script with the following code.
SCRIPT_ASSET_ID = "" ! cpdctl asset delete --asset-id {SCRIPT_ASSET_ID} --project-id {project_id}
Parent topic: Managing assets