public async execute()

in src/tasks/ECRPushImage/TaskOperations.ts [22:91]


    public async execute(): Promise<void> {
        this.dockerPath = await this.dockerHandler.locateDockerExecutable()

        let sourceImageRef: string

        if (this.taskParameters.forceDockerNamingConventions) {
            // The repository name can only contain lowercase letters, numbers, or - and _.
            this.taskParameters.repositoryName = this.taskParameters.repositoryName
                .toLowerCase()
                .replace(/[^a-z0-9-_.]/g, '')
        }

        if (this.taskParameters.imageSource === imageNameSource) {
            sourceImageRef = constructTaggedImageName(
                this.taskParameters.sourceImageName,
                this.taskParameters.sourceImageTag
            )
            console.log(tl.loc('PushImageWithName', sourceImageRef))
        } else {
            sourceImageRef = this.taskParameters.sourceImageId
            console.log(tl.loc('PushImageWithId', this.taskParameters.sourceImageId))
        }

        const authData = await getEcrAuthorizationData(this.ecrClient)
        if (!authData) {
            throw new Error(tl.loc('FailureToObtainAuthToken'))
        }

        let endpoint = ''
        let authToken = ''
        let proxyEndpoint = ''
        if (authData.proxyEndpoint) {
            endpoint = `${parse(authData.proxyEndpoint).host}`
        }
        if (!endpoint) {
            throw new Error(tl.loc('NoValidEndpoint', this.taskParameters.repositoryName))
        }
        if (authData.authorizationToken) {
            authToken = authData.authorizationToken
        }
        if (authData.proxyEndpoint) {
            proxyEndpoint = authData.proxyEndpoint
        }

        if (this.taskParameters.autoCreateRepository) {
            await this.createRepositoryIfNeeded(this.taskParameters.repositoryName)
        }

        const targetImageName = constructTaggedImageName(
            this.taskParameters.repositoryName,
            this.taskParameters.pushTag
        )
        const targetImageRef = `${endpoint}/${targetImageName}`
        await this.tagImage(sourceImageRef, targetImageRef)

        await loginToRegistry(this.dockerHandler, this.dockerPath, authToken, proxyEndpoint)

        await this.pushImageToECR(targetImageRef)

        if (this.taskParameters.outputVariable) {
            console.log(tl.loc('SettingOutputVariable', this.taskParameters.outputVariable, targetImageRef))
            tl.setVariable(this.taskParameters.outputVariable, targetImageRef)
        }

        if (this.taskParameters.removeDockerImage) {
            await this.removeDockerImage(sourceImageRef)
        }

        console.log(tl.loc('TaskCompleted'))
    }