1. Prerequisites
You must have Docker and the Go environment installed. Follow the installation instructions for your operating system.
2. Unexpected close on double-click in Windows
Flow cli cannot be run by double-clicking. You must run it from the command line.
3. Error on Windows: missing Location in call to Time.In
panic: time: missing Location in call to Time.In
goroutine 1 [running]:
time.Time.In(...)
/usr/local/Cellar/go/1.13.4/libexec/src/time/time.go:1126
gitlab.alibaba-inc.com/aone/flow-step-cli/util.beijingTime(0xc00018aab0, 0xa, 0xc00018aab0, 0xd)
/Users/lxliuxuan/go/src/gitlab.alibaba-inc.com/aone/flow-step-cli/util/time.go:18 +0x152
gitlab.alibaba-inc.com/aone/flow-step-cli/util.TimeFormat(0x1739b645658, 0x2, 0x2)
/Users/lxliuxuan/go/src/gitlab.alibaba-inc.com/aone/flow-step-cli/util/time.go:9 +0x5d
gitlab.alibaba-inc.com/aone/flow-step-cli/step.List(0xc00004b140, 0x0, 0x0)
/Users/lxliuxuan/go/src/gitlab.alibaba-inc.com/aone/flow-step-cli/step/list.go:27 +0x2f6
github.com/urfave/cli.(*Command).Run(0xc00009cea0, 0xc00004b080, 0x0, 0x0)
/Users/lxliuxuan/go/src/github.com/urfave/cli/command.go:163 +0x4c0
github.com/urfave/cli.(*App).RunAsSubcommand(0xc000035380, 0xc00004ae40, 0x0, 0x0)
/Users/lxliuxuan/go/src/github.com/urfave/cli/app.go:427 +0x9e9
github.com/urfave/cli.(*Command).startApp(0xc00009cb40, 0xc00004ae40, 0xc000dbca0, 0x40a4e1)
/Users/lxliuxuan/go/src/github.com/urfave/cli/command.go:278 +0x693
github.com/urfave/cli.(*Command).Run(0xc00009cb40, 0xc00004ae40, 0x0, 0x0)
/Users/lxliuxuan/go/src/github.com/urfave/cli/command.go:94 +0x9f2
github.com/urfave/cli.(*App).RunContext(0xc000035200, 0xa27300, 0xc00001e238, 0xc00004a080, 0x3, 0x4, 0x0, 0x0)
/Users/lxliuxuan/go/src/github.com/urfave/cli/app.go:306 +0x797
github.com/urfave/cli.(*App).Run(...)
/Users/lxliuxuan/go/src/github.com/urfave/cli/app.go:217
main.main()
/Users/lxliuxuan/go/src/gitlab.alibaba-inc.com/aone/flow-step-cli/main.go:111 +0xac4
To fix this issue, install the Go environment.
4. Can I use a custom port?
No, this is not supported. The authentication callback is hardcoded to use 127.0.0.1 on port 80 and cannot be changed.
5. Bypassing browser-based authentication
Flow cli uses the ~/.flow.json file for authentication. You can create this file manually to bypass the browser-based login flow. The file must contain the following content:
{"userToken":{"access_token":"ACCESS_TOKEN","token_type":"Bearer","user_id":"USER_ID"},"organization":{"error":"","message":"","id":"","createdAt":"","updatedAt":"","creatorId":"","name":"","logo":"","location":"","category":"","description":"","website":"","background":"","contactPhone":"","desiredMemberCount":"","isDeleted":"","py":"","pinyin":"","isPublic":false,"defaultRoleId":"","defaultOrgRoleId":"","okrProgressMode":"","defaultTeamId":"","openId":"","source":""}}
Replace ACCESS_TOKEN and USER_ID with your own values. You can obtain these values as follows:
-
Log in to the Alibaba Cloud DevOps pipeline. Right-click the page and select "View Page Source". In the page source, find the tbUserId value (this is your USER_ID) and the accessToken value (this is your ACCESS_TOKEN).
-
After replacing the placeholders, save the content to the
~/.flow.jsonfile.
6. Errors with no log output
When a custom step in a pipeline fails, the log area displays No logs.
This error occurs because the image specified for the step is private, and Alibaba Cloud DevOps does not have permission to pull it. To resolve this, change the image defined in your step.yaml file to a public image. For data security, do not store sensitive data in the image.
7. Using system environment variables in custom steps
To do this, replace the contents of the entry.sh file in the .step directory of your step with the following script. Then, republish the step.
#!/bin/bash
source /root/logger.sh
source /root/exec.sh
source /root/redline.sh
WORK_SPACE=/root/workspace
PLUGIN_DIR=/root/plugins
PROJECT_DIR=$WORK_SPACE/code
LOG_DIR=$WORK_SPACE/logs
TASK_DIR=$WORK_SPACE/task
CONTEXT_DIR=$WORK_SPACE/context
COMMAND_DIR=$WORK_SPACE/user_command.sh
ENV_DIR=$WORK_SPACE/env
TIMESTAMP=`date +%s`
DATETIME=`date +%Y-%m-%d-%H-%M-%S`
STEP_CONTEXT=$WORK_SPACE/stepContext
mkdir -p $PLUGIN_DIR
# Get step parameters
retry_times=0
while
INFO Get: $TASK_URL >> $LOG_DIR
curl --connect-timeout 20 --fail --insecure --location $TASK_URL >$TASK_DIR 2>>$LOG_DIR
[[ $? != '0' || ! -s $TASK_DIR || $(grep '"successful":false' $TASK_DIR) != '' ]] && ((retry_times < 3))
do
WARNING "Failed to get parameters. Retrying attempt $retry_times..."
WARNING RETRY... >> $LOG_DIR
(( retry_times++ ));
done
# Write environment variables to the context file
cat $TASK_DIR | jq -r '.envVars // "{\"WORK_SPACE\":\"/root/workspace\"}"' | jq -r "to_entries|map(\"\(.key)='\(.value|tostring)'\")|.[]" > $CONTEXT_DIR
# Write command information to user_command.sh
cat $TASK_DIR | jq -r '.command' > $COMMAND_DIR
if [[ ! -s $CONTEXT_DIR ]]; then
ERROR "Failed to get environment variables. Contact the system administrator."
ERROR BUILD ERROR
ERROR $BUILD_JOB_ID
exit 1;
fi
source $CONTEXT_DIR
export $(cut -d= -f1 $CONTEXT_DIR)
if [[ -f $STEP_CONTEXT ]]; then
source $STEP_CONTEXT
export $(cut -d= -f1 $STEP_CONTEXT)
fi
# Print an error message if fetching the credential fails
if [[ -z "$ERROR" ]]; then
SUCCESS Credential fetched successfully
else
ERROR $ERROR
fi
# Code repository path
if [[ $source ]]; then
INFO Using working directory $WORK_SPACE/$source
PROJECT_DIR=$WORK_SPACE/$source
else
WARNING "No working directory specified. Using default path $PROJECT_DIR"
fi
if [[ ! -d $PROJECT_DIR ]]; then
mkdir -p $PROJECT_DIR
fi
# System parameters, consistent with the old pipeline version
export PIPELINE_ID=$ENGINE_PIPELINE_ID
export PIPELINE_NAME=$ENGINE_PIPELINE_NAME
export BUILD_NUMBER=$ENGINE_PIPELINE_INST_NUMBER
export EMPLOYEE_ID=$operator
export PROJECT_DIR
export WORK_SPACE
export PLUGIN_DIR
export stepIdentifier
export STEP_CONTEXT
# Handle variables that need environment variable substitution
if [[ $PARAM_READY_TO_REPLACE_ENV ]]; then
for PARAM_KEY in $PARAM_READY_TO_REPLACE_ENV;
do
echo $PARAM_KEY="${!PARAM_KEY}" >> $ENV_DIR
done
source $ENV_DIR
export $(cut -d= -f1 $ENV_DIR)
fi
####################### Execute Step Script #############################
if [[ -x /root/pre.sh ]]; then
INFO Preparing step
step_exec /root/pre.sh
fi
INFO Executing step
step_exec /root/step.sh
exec_result=$?
if [[ "$exec_result" = "0" ]]; then
SUCCESS Step executed successfully
else
if [[ -x /root/catch.sh ]]; then
step_exec /root/catch.sh
fi
ERROR BUILD ERROR
ERROR $BUILD_JOB_ID
ERROR "Step execution failed with exit code: $exec_result"
fi
if [[ -x /root/final.sh ]]; then
step_exec /root/final.sh
fi
exit $exec_result