Creating a script asset with CPDCTL

Learn to create a script asset with Cloud Pak for Data command line interface (CPDCTL).

  1. 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.gz
    

    Check for the available Cloud Pak for Data versions in our GitHub releases.

  2. Extract downloaded archive.

     ! tar xzf cpdctl_linux_amd64.tar.gz
    
  3. Ensure that the cpdctl archive is in the current working directory and the system PATH.
     %%capture
     %env PATH={CWD}:{PATH}
    
  4. Check that CLI is accessible.
     ! cpdctl version
    
  5. 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')
    
  6. Open your script.
     with open('<test_script>', 'w') as f:
         f.write("echo OK")
    
  7. Create the new script asset.
     ! cpdctl asset script create --file <test_script> --project-id {project_id}
    
    When you run this line of code, you receive the asset ID in its output.
  8. List the script asset in the project.
     ! cpdctl asset search --type-name script --query 'test.sh' --project-id {project_id}
    
  9. 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